Guest Carnifex Posted August 15, 2010 Share Posted August 15, 2010 I have a problem with social.AddIgnore, because it makes an error in a case, it shouldn't make an error. Short description: Quote: params=parameters of the event "EVENT_CHAT_MESSAGE" social.AddIgnore(params.sender,params.sender) --> works fine Spammer [0] =params.sender common.CompareWString(Spammer [0] ,params.sende)==0 -> true social.AddIgnore(Spammer [0] ,Spammer [0] ) -> error: Game::LuaSocialAddIgnore: MainPlayer not found, details: int __cdecl Game::LuaSocialAddIgnore(struct lua_State *) source-code: Code: Global("Spammer", nil)Global("Spammercount",nil) Global("Chatmsg",{}) Global("Chatmsgcount",0) Global("LastEventAvatarWillBeRemovedDelay", 0) Global("debugmode",false) Global("synchronised",false) function SpamProtect(params) if debugmode then Chatmsg [Chatmsgcount] =params.msg Chatmsgcount=Chatmsgcount+1 end if params.chatType == CHAT_TYPE_ZONE then local spam=false for i = 1,3 do if common.CompareWString(params.msg,common.GetAddonRelatedText( "spam"..i ))==0 then spam=true end end if spam==true then local stillbanned=false for j=0,Spammercount [0] -1 do if common.CompareWString(Spammer [j] ,params.sender)==0 then stillbanned=true end --but this works o.O end if not stillbanned then social.AddIgnore(params.sender,params.sender) Spammer [Spammercount[0] ]=params.sender Spammercount [0] =Spammercount [0] +1 end end end end function SaveTabels() common.SetGlobalConfigSection("SpammerList",Spammer) common.SetGlobalConfigSection("SpammerListCount",Spammercount) if debugmode then common.SetGlobalConfigSection("ChatLog",Chatmsg) end end function OnEVENT_AVATAR_WILL_BE_REMOVED(param) --don't work good (copied from HealtDB) if LastEventAvatarWillBeRemovedDelay <= param.delay then SaveTabels() common.LogInfo("","Spiel beendet") end LastEventAvatarWillBeRemovedDelay = param.delay end function OnEVENT_AVATAR_CLIENT_ZONE_CHANGED(param) SaveTabels() end function OnEventSecondTimer() --I seperated this out of the Init, because it could be the reason of the error. --> I get nevertheless the error. if not synchronised then synchronised=true if Spammercount [0] >0 then for i=0,Spammercount [0] -1 do social.AddIgnore(Spammer ,Spammer ) --Game::LuaSocialAddIgnore: MainPlayer not found, details: int __cdecl Game::LuaSocialAddIgnore(struct lua_State *) end end end end function Init() common.RegisterEventHandler(SpamProtect, "EVENT_CHAT_MESSAGE" ) common.RegisterEventHandler(OnEVENT_AVATAR_WILL_BE_REMOVED, "EVENT_AVATAR_WILL_BE_REMOVED") --don't save after every exit? common.RegisterEventHandler(OnEVENT_AVATAR_CLIENT_ZONE_CHANGED, "EVENT_AVATAR_CLIENT_ZONE_CHANGED") common.RegisterEventHandler(OnEventSecondTimer, "EVENT_SECOND_TIMER" ) Spammer=common.GetGlobalConfigSection("SpammerList") Spammercount=common.GetGlobalConfigSection("SpammerListCount") if not Spammer then Spammer = {} end if not Spammercount then Spammercount={} Spammercount [0] =0 end --common.LogInfo("",Spammer [0] ) --has the value "Tjfgfhrthrth" and common.CompareWString(Spammer [0] ,common.GetAddonRelatedText(TXT_WITH_HIM)==0 was true --social.AddIgnore(Spammer [0] ,Spammer [0] ) --api says, that first param is a wstring with the name (Goldseller still excist and spam) -- why it make the error Game::LuaSocialAddIgnore: MainPlayer not found, details: int __cdecl Game::LuaSocialAddIgnore(struct lua_State *) end Init() Can someone help me, pls? BTW: how can I get the length of a tabel, so that Global("Spammercount",nil) is not necessary? --> in the Lua 5.1 manual stands, that #t ist the length of the tabel t. Do this work (I have never see this in an other addon) Quote Link to comment Share on other sites More sharing options...
Guest Jampire Posted August 16, 2010 Share Posted August 16, 2010 Переведите на русский плз Quote Link to comment Share on other sites More sharing options...
Guest mehael Posted August 16, 2010 Share Posted August 16, 2010 MainPlayer is created not at start AO, so you should add check: Code: function OnEventSecondTimer() if avatar.IsExist() then if not synchronised then synchronised=true if Spammercount [0] >0 then for i=0,Spammercount [0] -1 do social.AddIgnore(Spammer ,Spammer ) end end end end end I did not check this code, but it should work.. Quote: how can I get the length of a tabel, so that Global("Spammercount",nil) is not necessary? -- Code: local tableSize = GetTableSize( table ) I am sorry for my English Quote Link to comment Share on other sites More sharing options...
Nikon Posted August 16, 2010 Share Posted August 16, 2010 Tables in LUA Quote: Notice that the indexing into the array starts at 1, not at zero + Code: local tableSize = table.getn( table ) + AO uses LUA 5.0.NNN. + libraries coroutine, table, string, math. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 16, 2010 Share Posted August 16, 2010 @mehael: thx, with avatar.IsExist() it do not make an error (so my avatar do not excist in init? the avatar is creadet a few seconds later? And I thought, that the error is caused by the player, who should be banned^^) BTW: I added a check, if the goldseller is still ignored. now it is perfect Quote: Notice that the indexing into the array starts at 1, not at zero One more reason, that I do not like lua^^ BTW: Have you in the russion AO also problems with goldsellers or is it not necessary to make this addon working in the russan version? Quote Link to comment Share on other sites More sharing options...
ramirez Posted August 16, 2010 Share Posted August 16, 2010 Code: Global( "Spammer", {} )Global( "Chatmsg", {} )Global( "debugmode", false )Global( "logout", false )Global( "spam", {} )Global( "on", {} )---------------------------------------------------------------------------------- MAIN--------------------------------------------------------------------------------function LoadTables() Spammer = common.GetGlobalConfigSection( "SpammerList" ) or {} if debugmode then Chatmsg = common.GetGlobalConfigSection( "ChatLog", Chatmsg ) or {} endend--------------------------------------------------------------------------------function SaveTables() common.SetGlobalConfigSection( "SpammerList", Spammer ) if debugmode then common.SetGlobalConfigSection( "ChatLog", Chatmsg ) endend--------------------------------------------------------------------------------function Synchronize() for _, entry in ipairs( Spammer ) do social.AddIgnore( entry, entry ) endend--------------------------------------------------------------------------------function HasEntry( tab, sample ) for _, entry in ipairs( tab ) do if common.CompareWString( entry, sample ) == 0 then return true end end return falseend--------------------------------------------------------------------------------function common.RegisterEventHandlers( handlers ) for event, handler in pairs( handlers ) do common.RegisterEventHandler( handler, event ) endend---------------------------------------------------------------------------------- HANDLERS--------------------------------------------------------------------------------on [ "EVENT_CHAT_MESSAGE" ] = function( event ) local msg, sender = event.msg, event.sender if debugmode then table.insert( Chatmsg, msg ) end if event.chatType == CHAT_TYPE_ZONE and HasEntry( spam, msg ) and not HasEntry( Spammer, sender ) then social.AddIgnore( sender, sender ) table.insert( sender ) endend--------------------------------------------------------------------------------on [ "EVENT_AVATAR_WILL_BE_REMOVED" ] = function( event ) if not logout then SaveTables() logout = true endend--------------------------------------------------------------------------------on [ "EVENT_AVATAR_LOGOUT_CANCELLED" ] = function( event ) logout = falseend--------------------------------------------------------------------------------on [ "EVENT_AVATAR_CLIENT_ZONE_CHANGED" ] = SaveTableson [ "EVENT_AVATAR_CREATED" ] = Synchronize----------------------------------------------------------------------------------------------------------------------------------------------------------------function Init() for i = 1, 33 do table.insert( spam, common.GetAddonRelatedText( string.format( "spam%02d", i ) ) ) end LoadTables() common.RegisterEventHandlers( on ) if avatar.IsExist() then Synchronize() endend--------------------------------------------------------------------------------Init() There can be a few glitches in this code, but hey, i know, you can fix it. =) Quote Link to comment Share on other sites More sharing options...
SLA Posted August 16, 2010 Share Posted August 16, 2010 Quote: so my avatar do not excist in init? the avatar is creadet a few seconds later? Yes, Init() is executing during the "Loading..." splash screen, and avatar appears only AFTER this splash screen, several seconds later.But there is an event EVENT_AVATAR_CREATED which fires when your avatar gets an ID, which means you can start using avatar.GetId() and many other avatar-related functions. Many addons are using this event.Quote: BTW: Have you in the russion AO also problems with goldsellers or is it not necessary to make this addon working in the russan version? Truth to say, no, we don't have those terrible spam-bots, like in English servers, which spams the same phrase into chat non-stop, every several seconds... We just have normal players, who sometimes writes a single message "wtb gold" or "wtb crystals". But on English servers this is TERRIBLE problem. Your addon will be very popular! BTW, in API 1.1.03, EVENT_CHAT_MESSAGE got a new parameter - spamWeight, which probably will solve the problem somehow Quote: spamWeight: number (integer) - Spam-weight of the message. If it is < 100, then it is NOT spam, otherwise it IS spam. Quote Link to comment Share on other sites More sharing options...
Nikon Posted August 16, 2010 Share Posted August 16, 2010 Нет, чтобы выдать человеку нормально работающий код Quote Link to comment Share on other sites More sharing options...
ramirez Posted August 16, 2010 Share Posted August 16, 2010 Код переписать - быстро, а аддон делать и тестить - долго. =) А у Carnifex'а аддон уже есть. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 16, 2010 Share Posted August 16, 2010 @SLA: and how do spamWeight works? Because it is only for one message, I think it will not check, if one character sends everytime the same messages. And if it analyse the msg, it is only so good as our GM's work on the spamfilters (and this is at the moment not so good^^) @Ramirez: thx for you code. I still have a working version, but your code is much more elegant (you have more experience in programming with lua^^) One question for the next step: Is it possible to remove messages from the chatwindow or to say, which received message is shown and which not? I want to add this, so that players with an buggy friendslist (internal error, because player on it has delete himself) also do not see the goldseller-spam. (Is it not easy to understand some parts of the api, using the google translator^^) Code: Global( "Spammer", {} )Global( "Chatmsg", {} ) Global( "debugmode", false ) Global( "logout", false ) Global( "spam", {} ) Global( "on", {} ) -------------------------------------------------------------------------------- -- MAIN -------------------------------------------------------------------------------- function LoadTables() Spammer = common.GetGlobalConfigSection( "SpammerList" ) or {} if debugmode then Chatmsg = common.GetGlobalConfigSection( "ChatLog", Chatmsg ) or {} end end -------------------------------------------------------------------------------- function SaveTables() common.SetGlobalConfigSection( "SpammerList", Spammer ) if debugmode then common.SetGlobalConfigSection( "ChatLog", Chatmsg ) end end -------------------------------------------------------------------------------- function Synchronize() for _, entry in ipairs( Spammer ) do if not HasEntry( Spammer, entry ) then social.AddIgnore( entry, entry ) end end end -------------------------------------------------------------------------------- function HasEntry( tab, sample ) for _, entry in ipairs( tab ) do if common.CompareWString( entry, sample ) == 0 then return true end end return false end -------------------------------------------------------------------------------- function common.RegisterEventHandlers( handlers ) for event, handler in pairs( handlers ) do common.RegisterEventHandler( handler, event ) end end -------------------------------------------------------------------------------- -- HANDLERS -------------------------------------------------------------------------------- on [ "EVENT_CHAT_MESSAGE" ] = function( event ) local msg, sender = event.msg, event.sender if debugmode then table.insert( Chatmsg, msg ) end if event.chatType == CHAT_TYPE_ZONE and HasEntry( spam, msg ) and not HasEntry( Spammer, sender ) then social.AddIgnore( sender, sender ) table.insert( Spammer, sender ) end end -------------------------------------------------------------------------------- on [ "EVENT_AVATAR_WILL_BE_REMOVED" ] = function( event ) if not logout then SaveTables() logout = true end end -------------------------------------------------------------------------------- on [ "EVENT_AVATAR_LOGOUT_CANCELLED" ] = function( event ) logout = false end -------------------------------------------------------------------------------- on [ "EVENT_AVATAR_CLIENT_ZONE_CHANGED" ] = SaveTables on [ "EVENT_AVATAR_CREATED" ] = Synchronize -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function Init() for i = 1, 3 do table.insert( spam, common.GetAddonRelatedText( string.format( "spam%02d", i ) ) ) end LoadTables() common.RegisterEventHandlers( on ) end -------------------------------------------------------------------------------- Init() (updatet Synchronize --> check if spammer is still banned + deletet synchronize from init --> no sense (it is always if false^^)) Quote Link to comment Share on other sites More sharing options...
ramirez Posted August 16, 2010 Share Posted August 16, 2010 I think that "Synchronize" part is not needed at all. Your ignorlist is saved on server, so why bother? =) You can "ignore" some person only once, and he (or she) will remain in ignorelist as long as you wanted. You can't interact with "chat" or any other standard addon, no matter what. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 16, 2010 Share Posted August 16, 2010 but the ignorlist ist charbounded. With the "Synchronize" part a Goldspammer, which was banned with one character, will be automaticly banned at all other characters. Quote Link to comment Share on other sites More sharing options...
ramirez Posted August 16, 2010 Share Posted August 16, 2010 Quote: but the ignorlist ist charbounded. Ok, so you have your "Spammer" list with some number of charnames in it. So how exactly you can catch and ban all other characters at spammer's account? All that "Synchronise" part can do is adding all this names to ignorlist again. But hey, they already there. =)Quote: BTW: What a sense has the a in "for a, entry in ipairs( Spammer ) do ..." (I know from prolog what _ is^^) "a" is table index, "entry" is table value.In Lua "_" is valid string identifier, like "o_O", "^_^" and so on. So you can use it like this Spammer [ _ ] = something. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 16, 2010 Share Posted August 16, 2010 oh sry, i do not wrote it very clearly With the "Synchronize" part a Goldspammer, which was banned with one OF YOUR character, will be automaticly banned at all YOUR other characters. -> ignorelist from SpamProtect is not charbounded, it is only clientbounded BTW: @2nd part: How could you read this? I edited it out, because I answerd the question by my self^^ BTW²: If I am right, that is also not possible to write something as an infoline in the chat? BTW³: can you say me, what Quote: wtChat [usr] userdata: 03C27758 is? (you can find it at the end of Mods/Docs/api_v1.xml) Bug-report: your code for savin the tabels only work, if you are logging out to swich the character, but it does not work, if yoo leave the game completly (over the menu) Quote Link to comment Share on other sites More sharing options...
ramirez Posted August 17, 2010 Share Posted August 17, 2010 Quote: With the "Synchronize" part a Goldspammer, which was banned with one OF YOUR character, will be automaticly banned at all YOUR other characters. Oh well, that was stupid of me. =) Thx for answer.Quote: If I am right, that is also not possible to write something as an infoline in the chat? You're right.Quote: you can find it at the end of Mods/Docs/api_v1.xml I can't find anything like this. What's this about? Quote Link to comment Share on other sites More sharing options...
SLA Posted August 17, 2010 Share Posted August 17, 2010 Quote: you can find it at the end of Mods/Docs/api_v1.xml api_v1.xml - we don't have this file in Mods\Docs. Can you post it here?Quote: Bug-report: your code for savin the tabels only work, if you are logging out to swich the character, but it does not work, if yoo leave the game completly (over the menu) The same problem existed in early "AoSimpleCoords" versions. That's why I don't recommend to save anything on EVENT_AVATAR_WILL_BE_REMOVED, but instead, save your Spammer-list after every Spammer-list change.Quote: If I am right, that is also not possible to write something as an infoline in the chat? We definitely have to ask game developers to add this ability. As well as some other abilities, like getting item/spell icons, etc, etc...Quote: @SLA: and how do spamWeight works? I don't know. The short description I have translated above, is the only info, and there is no more information about it.Currently I'm on vacation, and I have NO access to AO 1.1.03 game client (because 600+ MB patch is too large, and internet connection here is too slow), so I have to return at home to test it. I will be back at home in several days Currently my testing abilities are just like yours, Carnifex - I have a new API, but I can't test anything )But I guess, the server tracks spammers itself, and marks all messages with different spamWeights. And game client probably just skips those messages which spamWeight is >= 100. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 17, 2010 Share Posted August 17, 2010 Quote: api_v1.xml - we don't have this file in Mods\Docs. Can you post it here? Now I remember, I found this anywhere in your russian forum and copied it to this folder. (look at the attachment, but it is not up to date...)Quote: The same problem existed in early "AoSimpleCoords" versions. That's why I don't recommend to save anything on EVENT_AVATAR_WILL_BE_REMOVED, but instead, save your Spammer-list after every Spammer-list change. Ok, I will do thisBut I Have now a second problem. If you have an buggy friendslist and you yoin the game, you will se a spam of "internal errors" for every spammer, the addon tried to add. To fix this, i have addedCode: common.RegisterEventHandler(onInternalError, "EVENT_AVATAR_FRIEND_IGNORE_LISTS_ERROR") --this in Init--and this:function onInternalError(errorname) if (not internal_error) and errorname.sysError=="ENUM_FriendIgnoreListError_ServiceNotReady" then internal_error=true endend--and in the event OnEVENT_AVATAR_CREATED this:if ignores and (not isinTable(ignores,curentspammer)) and (not internal_error) then social.AddIgnore(curentspammer,curentspammer)end but it seems, that onInternalError is called complety after OnEVENT_AVATAR_CREATED and so it do not solve the problem. has someone an idea to this? --> Edit: I have a plan, how to solve this (I will do this this evening and I planed to add a function, so that you can declasre ingame a msg as a goldsellermsg)BTW: "if a and b the..." and a is false --> check lua now b or ignore lua b?Here the current soure-code of SpamProtect: xchrisx.bplaced.net/SpamProtect.zipFile: api_xml.zip Quote Link to comment Share on other sites More sharing options...
Setras Posted August 17, 2010 Share Posted August 17, 2010 You can write a very simple small addon that will display the spam weight of last written message and experiment whispering yourself. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 17, 2010 Share Posted August 17, 2010 the problem is, that SLA is not at home and I have v. 1.1.00.44^^ Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 18, 2010 Share Posted August 18, 2010 I think, this should work now: Code: function OnEVENT_AVATAR_CREATED() if table.getn(Spammer)>0 then local ignores = social.GetIgnoreList() if ignores and (not isinTable(ignores,Spammer [1] )) then social.AddIgnore(Spammer [1] ,Spammer [1] ) end if table.getn(Spammer)>1 then timer=3 end end function OnEventSecondTimer() if timer>1 then timer=timer-1 elseif timer==1 then for i,curentspammer in ipairs(Spammer) do local ignores = social.GetIgnoreList() if ignores and (not i==1) and (not isinTable(ignores,curentspammer)) and (not internal_error) then social.AddIgnore(curentspammer,curentspammer) end end end end function onInternalError(errorname) if (not internal_error) and errorname.sysError=="ENUM_FriendIgnoreListError_ServiceNotReady" then internal_error=true end end BTW: is it possible to make that "/Schlachtzug text here" automaticly call "/raid text here" (our gm's have translated raid with schlachtzug, but they do not have added an new slashcommand dor it...) Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted August 18, 2010 Share Posted August 18, 2010 Have anybody an idea, waht causes this error: Code: Error: addon SpamProtect: Error: addon SpamProtect: Error: addon SpamProtect: func: ?, ?, line: -1, defined: C, line: -1, [C] Error: addon SpamProtect: func: Init, global, line: 106, defined: Lua, line: 100, [string "Mods/Addons/SpamProtect/SpamProtect.lua"] Error: addon SpamProtect: func: ?, ?, line: 131, defined: main, line: 0, [string "Mods/Addons/SpamProtect/SpamProtect.lua"] Error: addon SpamProtect: Attempt to read from undeclared global variable: OnReactionOk if I comment the reactionshandler out, the buttons are shown without any error (but of curse the do not work^^). if i comment it in i became this error at init. (you must type /gsaddmsg to oben the window) BTW: I am for the next to weeks not at home, so do not wonder if i do not reply... Quote Link to comment Share on other sites More sharing options...
SLA Posted August 25, 2010 Share Posted August 25, 2010 Because OnReactionOK is not OnReactionOk. Note the uppercase and lowercase 'K' =) Quote Link to comment Share on other sites More sharing options...
SLA Posted August 25, 2010 Share Posted August 25, 2010 Quote: api_v1.xml OMG, LOL, now I remember, this api_v1.xml was posted by Skillcoder almost a year ago in the 3-rd topic of THIS forum:http://ui9.ru/forum/develop/topic/3 ))))Quote: BTW: is it possible to make that "/Schlachtzug text here" automaticly call "/raid text here" (our gm's have translated raid with schlachtzug, but they do not have added an new slashcommand dor it...) No, we can't alter the chat in any way. We can't alter messages, and we can't write to the chat. All those functions are blocked to protect the chat against spammers ) Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted September 5, 2010 Share Posted September 5, 2010 thx, a typical mistake, which you can easily overlook... btw: in the attachment you can find the current version of SpamProtect: -several bugfixes -/gsaddmsg (add a message to an alternativ (not the txt's) list of spam-messages at your client an ban the sender) -/gsunban (unban a player in ingame-ignorelist and SpamProtect-ignorelist) -/gsdelmsg (unmark a message as goldseller-message) I still have to test it and after this I can think over an release. Quote Link to comment Share on other sites More sharing options...
Guest Carnifex Posted September 8, 2010 Share Posted September 8, 2010 wtf, why is "(not 1==2)" false? o.O --> ah (not (1==2)) is true, I think lua negate the one and compare it with two, lol Info: addon SpamProtect: i: 1 Info: addon SpamProtect: wtf, i==1 <--I understand this Info: addon SpamProtect: i: 2 Info: addon SpamProtect: wtf, i==1 <-- but I do not understand this... Info: addon SpamProtect: i: 3 Info: addon SpamProtect: wtf, i==1 <-- ...and this, wtf have someone an explanation for this? BTW: i~=1 works, but what is the different between i~=1 and not i==1 o.O Quote Link to comment Share on other sites More sharing options...
Recommended Posts