ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
3.4 vb sdk (Sdk)
3.4 vb sdk // SdkananasFeb 8, 2003, 4:20pm
What Andras wrote will fix some crashes, that's for sure.
But why do you identify the people by name at all? Citizen numbers will not change as often as names and a comparison of two integers is way faster than a string comparison orgy - plus you could use switch/case very comfortable like this : #define CIT_TheMask 12345 (well, put the correct cit. numbers there ;) #define CIT_Builderz 12346 (... and some more) #define CIT_Cadet 13254 void handle_avatar_add (void) { int Session; switch (aw_int (AW_AVATAR_CITIZEN)) { case CIT_TheMask : case CIT_Builderz : (... and some more) case CIT_Cadet : Session = aw_int(AW_AVATAR_SESSION); aw_whisper (Session, "Whisper password to gain rights"); break; } } In handle_chat() you could choose a similar solution. As you would need the cit. number #defines in several places, it would be helpful to put them into a header file that you can #include where you need the definitions. Optional you could hold all citizen numbers in an integer array and compare those in a loop, a little slower but easier to add more citizens. [View Quote] .duo.Feb 17, 2003, 10:15am
No, that won't make a difference. I just use the booleans to know who is
who, and I track name changes and can just reprogram the bot. Cit numbers are a better idea since identifying by names just won't work >_< You see, it no longer detects matches because there are the 1000 unused characters in the strings, which appear as dashes... I ended up making a VB bot as an equivelent, and it doesn't work either ROFL. It'll be a lot harder to understand because I'm horrible at vb, but here it is: Dim Cameron999 As Boolean Dim NelXaga As Boolean Dim SuperGuy3 As Boolean Dim TSAAgent1 As Boolean Dim DSdarkknight As Boolean Dim Ssl As Boolean Dim Aeo As Boolean Dim Reaper As Boolean 'DS dark knight,TSA Agent 1,Cameron999,NelXaga,Ssl.,Aeo,Reaper. Private Sub Command1_Click() sdk.QuickStop sdk.AwDestroy sdk.AwTerm End End Sub Private Sub Form_Load() sdk.AwInit AW_BUILD sdk.EnableDefaultEvents sdk.EnableDefaultCallbacks sdk.QuickStart 342836, "zero", "RightsBot", "DuoBot", "jediwrld", 0, 0, 0, 0, 0 Cameron999 = False NelXaga = False SuperGuy3 = False TSAAgent1 = False DSdarkknight = False Ssl = False Aeo = False Reaper = False Call ProcessRights End Sub Private Sub sdk_EventAvatarAdd() aname = sdk.AwAvatarName asession = sdk.AwAvatarSession sdk.AwCitizenAttributesByName (aname) anumber = sdk.AwCitizenNumber sdk.AwSay aname sdk.AwSay asession sdk.AwSay anumber 'Check for entering builders and prompt them for rights password If aname = "Cameron999" Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "NelXaga" Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "SuperGuy3" Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "TSA Agent 1" Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "DS dark knight" Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "Ssl." Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "Aeo" Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = "Reaper." Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub If aname = ".Duo." Then sdk.AwWhisper asession, "Please whisper your password to me to gain rights.": Exit Sub End Sub Private Sub sdk_EventAvatarDelete() aname = sdk.AwAvatarName If aname = "Cameron999" Then Cameron999 = False If aname = "NelXaga" Then NelXaga = False If aname = "SuperGuy3" Then SuperGuy3 = False If aname = "TSA Agent 1" Then TSAAgent1 = False If aname = "DS dark knight" Then DSdarkknight = False If aname = "Ssl." Then Ssl = False If aname = "Aeo" Then Aeo = False If aname = "Reaper." Then Reaper = False Call ProcessRights End Sub Private Sub sdk_EventChat() aname = sdk.AwAvatarName asession = sdk.AwChatSession amessage = sdk.AwChatMessage sdk.AwCitizenAttributesByName (aname) anumber = sdk.AwCitizenNumber 'Check for passwords and who is saying them, otherwise anyone could get rights. If sdk.AwChatType = AW_CHAT_WHISPER Then If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "Cameron999" Then If anumber = "350803" Then Cameron999 = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "NelXaga" Then If anumber = "337709" Then NelXaga = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "SuperGuy3" Then If anumber = "347525" Then SuperGuy3 = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "TSA Agent 1" Then If anumber = "341102" Then TSAAgent1 = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "DS dark knight" Then If anumber = "339192" Then DSdarkknight = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "Ssl." Then If anumber = "334597" Then Ssl = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "Aeo" Then If anumber = "336611" Then Aeo = True End If End If End If If amessage = "REMOVED AS A SECURITY PRECAUTION :-P" Then If aname = "Reaper." Then If anumber = "338925" Then Reaper = True End If End If End If End If Call ProcessRights End Sub Public Sub ProcessRights() 'Define strings that will eventually be passed into the world rights list. Dim b As String 'Build Dim ed As String 'Eminent Domain Dim ps As String 'Public Speaker Dim e As String 'Eject Dim bt As String 'Bots 'Give rights to the CT bosses b = "342836,312237" ed = "342836,312237" ps = "342836,312237" e = "342836,312237" bt = "342836,312237" 'Check who has logged in and give them rights If Cameron999 = True Then b = b & ",350803" ed = ed & ",350803" ps = ps & ",350803" e = e & ",350803" bt = bt & ",350803" End If If NelXaga = True Then b = b & ",337709" ed = ed & ",337709" ps = ps & ",337709" e = e & ",337709" bt = bt & ",337709" End If If SuperGuy3 = True Then b = b & ",347525" ed = ed & ",347525" ps = ps & ",347525" e = e & ",347525" bt = bt & ",347525" End If If TSAAgent1 = True Then b = b & ",341102" ed = ed & ",341102" ps = ps & ",341102" e = e & ",341102" bt = bt & ",341102" End If If DSdarkknight = True Then b = b & ",339192" ed = ed & ",339192" ps = ps & ",339192" e = e & ",339192" bt = bt & ",339192" End If If Ssl = True Then b = b & ",334597" ed = ed & ",339192" ps = ps & ",339192" e = e & ",339192" bt = bt & ",339192" End If If Aeo = True Then b = b & ",336611" ed = ed & ",336611" ps = ps & ",336611" e = e & ",336611" bt = bt & ",336611" End If If Reaper = True Then b = b & ",338925" ed = ed & ",338925" ps = ps & ",338925" e = e & ",338925" bt = bt & ",338925" End If 'Process Rights sdk.AwWorldBuildRight = b sdk.AwWorldEminentDomainRight = ed sdk.AwWorldPublicSpeakerRight = ps sdk.AwWorldEjectRight = e sdk.AwWorldBotsRight = bt End Sub I'm also making a more advanced rights bot later. ----- Original Message ----- From: "ananas" <vha at oct31.de> Newsgroups: sdk Sent: Saturday, February 08, 2003 1:20 PM Subject: Re: 3.4 vb sdk > What Andras wrote will fix some crashes, that's for sure. > > But why do you identify the people by name at all? > Citizen numbers will not change as often as names and > a comparison of two integers is way faster than a string > comparison orgy - plus you could use switch/case very > comfortable like this : > > #define CIT_TheMask 12345 (well, put the correct cit. numbers there ;) > #define CIT_Builderz 12346 > (... and some more) > #define CIT_Cadet 13254 > > void handle_avatar_add (void) > { > int Session; > > switch (aw_int (AW_AVATAR_CITIZEN)) > { > case CIT_TheMask : > case CIT_Builderz : > (... and some more) > case CIT_Cadet : > Session = aw_int(AW_AVATAR_SESSION); > aw_whisper (Session, "Whisper password to gain rights"); > break; > } > } > > In handle_chat() you could choose a similar solution. As you would > need the cit. number #defines in several places, it would be helpful > to put them into a header file that you can #include where you need > the definitions. > > Optional you could hold all citizen numbers in an integer array > and compare those in a loop, a little slower but easier to add > more citizens. > > [View Quote] .duo.Feb 17, 2003, 11:08am
Sorry, read your post too quickly. Yeah, thats a great idea, it'll work a
lot better. Thank you. Could someone check out my VB anyway? heh heh heh [View Quote] .duo.Feb 17, 2003, 12:52pm
Oh, the bot mainly works, its just that strcat still crashes it >_< BTW, is
there anyway to add CTs with a bot? Code (RightsBot.cpp): #define AW_STATIC #include <iostream.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <aw.h> #include "bteam.h" void handle_avatar_add (void); void handle_chat (void); void handle_avatar_delete (void); void ProcessRights (); char* copya (char* t); bool CheckString (char* o,char* t); char* addtext (char* o,char* t); int StringLength (char* t); bool Cameron999 = false; bool NelXaga = false; bool SuperGuy3 = false; bool TSAAgent1 = false; bool DSdarkknight = false; bool Ssl = false; bool Aeo = false; bool Reaper = false; bool Duo = false; void main (int argc, char *argv[]) { int rc; //API if (rc = aw_init (AW_BUILD)) { cout<<"Unable to initialize the API (reason %d)\n"<<rc; } //Set events aw_event_set (AW_EVENT_AVATAR_ADD, handle_avatar_add); aw_event_set (AW_EVENT_CHAT, handle_chat); aw_event_set (AW_EVENT_AVATAR_DELETE, handle_avatar_delete); aw_state_change (); for (;;) { if (aw_wait (1000)) { break; } } //Bot Instance if (rc = aw_create (0, 0, 0)) { cout<<"Unable to create bot instance (reason %d)\n"<<rc; exit (1); } //Login Bot aw_string_set (AW_LOGIN_NAME, "RightsBot"); aw_int_set (AW_LOGIN_OWNER, 342836); aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, "zero"); aw_string_set (AW_LOGIN_APPLICATION, "DuoBot: RightsBot"); if (rc = aw_login ()) { cout<<"Unable to login (reason "<<rc<<")\n"; } //Enter Bot Into World if (rc = aw_enter ("Jediwrld")) { printf("Unable to enter world (reason %d)\n", rc); exit (1); } puts (aw_string (AW_WORLD_WELCOME_MESSAGE)); //Go to place aw_int_set (AW_MY_X, 0000); aw_int_set (AW_MY_Z, 0000); aw_int_set (AW_MY_YAW, 0000); aw_int_set (AW_MY_TYPE, 0); aw_int_set (AW_MY_GESTURE, 0); if (rc = aw_state_change ()) { cout<<"Unable to change state (reason %d)\n"<<rc; exit (1); } ProcessRights(); //Main event loop while (!aw_wait (-1)) ; //Close Bot aw_destroy (); aw_term (); } void handle_avatar_add (void) { int session; session = aw_int(AW_AVATAR_SESSION); switch (aw_int (AW_AVATAR_CITIZEN)) { case CIT_Cameron999: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_NelXaga: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_SuperGuy3: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_TSAAgent1: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_DSdarkknight: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_Ssl: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_Aeo: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_Reaper: { aw_whisper(session,"Whisper password to gain rights"); break; } case CIT_Duo: { aw_whisper(session,"Whisper password to gain rights"); break; } } } void handle_chat () { int session; session = aw_int(AW_CHAT_SESSION); if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶La®ge Stinky Gorillas Basking In The Sun¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_Cameron999) { Cameron999 = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶Nøøb Hater¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_NelXaga) { NelXaga = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶find it Soon¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_SuperGuy3) { SuperGuy3 = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶©racker Bobbers¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_TSAAgent1) { TSAAgent1 = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶Sme||¥ little crag monkeys¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_DSdarkknight) { DSdarkknight = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶Rotten Bannanas Basking in the Sün¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_Ssl) { Ssl = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶§trange passwords are hard to crack¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_Aeo) { Aeo = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶Che× Mix is Evil¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_Reaper) { Reaper = true; } } else if(!stricmp(aw_string(AW_CHAT_MESSAGE),"¶WOOFERS¶")) { if(aw_int (AW_AVATAR_CITIZEN) == CIT_Duo) { Duo = true; } } else { //Do nothing } ProcessRights(); } void handle_avatar_delete () { int session; session = aw_int(AW_AVATAR_SESSION); switch (aw_int (AW_AVATAR_CITIZEN)) { case CIT_Cameron999: { Cameron999 = false; break; } case CIT_NelXaga: { NelXaga = false; break; } case CIT_SuperGuy3: { SuperGuy3 = false; break; } case CIT_TSAAgent1: { TSAAgent1 = false; break; } case CIT_DSdarkknight: { DSdarkknight = false; break; } case CIT_Ssl: { Ssl = false; break; } case CIT_Aeo: { Aeo = false; break; } case CIT_Reaper: { Reaper = false; break; } case CIT_Duo: { Reaper = false; break; } } ProcessRights(); } void ProcessRights() { char* b = new char[1024]; char* ed = new char[1024]; char* ps = new char[1024]; char* e = new char[1024]; char* bt = new char[1024]; b = "312237"; ed = "312237"; ps = "312237"; e = "312237"; bt = "342836,312237"; if(Cameron999 == true) { strcat(b,",350803"); strcat(ed,",350803"); strcat(ps,",350803"); strcat(e,",350803"); strcat(bt,",350803"); } if(NelXaga == true) { strcat(b,",337709"); strcat(ed,",337709"); strcat(ps,",337709"); strcat(e,",337709"); strcat(bt,",337709"); } if(SuperGuy3 == true) { strcat(b,",347525"); strcat(ed,",347525"); strcat(ps,",347525"); strcat(e,",347525"); strcat(bt,",347525"); } if(TSAAgent1 == true) { strcat(b,",341102"); strcat(ed,",341102"); strcat(ps,",341102"); strcat(e,",341102"); strcat(bt,",341102"); } if(DSdarkknight == true) { strcat(b,",339192"); strcat(ed,",339192"); strcat(ps,",339192"); strcat(e,",339192"); strcat(bt,",339192"); } if(Ssl == true) { strcat(b,",334597"); strcat(ed,",334597"); strcat(ps,",334597"); strcat(e,",334597"); strcat(bt,",334597"); } if(Aeo == true) { strcat(b,",336611"); strcat(ed,",336611"); strcat(ps,",336611"); strcat(e,",336611"); strcat(bt,",336611"); } if(Reaper == true) { strcat(b,",338925"); strcat(ed,",338925"); strcat(ps,",338925"); strcat(e,",338925"); strcat(bt,",338925"); } if(Duo == true) { strcat(b,",342836"); strcat(ed,",342836"); strcat(ps,",342836"); strcat(e,",342836"); } aw_string_set (AW_WORLD_BUILD_RIGHT, b); aw_string_set (AW_WORLD_EMINENT_DOMAIN_RIGHT, ed); aw_string_set (AW_WORLD_PUBLIC_SPEAKER_RIGHT, ps); aw_string_set (AW_WORLD_EJECT_RIGHT, e); aw_string_set (AW_WORLD_BOTS_RIGHT, bt); aw_world_attributes_change(); } Code (bteam.h): #define CIT_Cameron999 350803 #define CIT_NelXaga 337709 #define CIT_SuperGuy3 347525 #define CIT_TSAAgent1 341102 #define CIT_DSdarkknight 339192 #define CIT_Ssl 334597 #define CIT_Aeo 336611 #define CIT_Reaper 338925 #define CIT_Duo 342836 andrasFeb 17, 2003, 3:12pm
[View Quote]
<snip>
The meaning of your code snippet as follows: 1, when you define char *b, you are creating a pointer. 2, when you assign a new char[1024] to it, this pointer will point to a 1024 character long string which content is unknown (not initialized). 3, when you assign "312237" to the character pointer b - it will point to the 7 character long string which content will be "312237\0" (\0 is the NULL character). 4, when you strcat( b, " 350803") then you try to expand the already defined string ("312237\0") by an additional 7 characters which you can't do since there is no room for the excess character in that string (actually that string is even a constant, so it is embedded into the code you wrote). This is how the memory looks in your case: ---------------------- | your program | \ | | code section | | / the data section after the strcat(b,",350803"); instruction will look like: | 312237\0 | \ <--| | 312237, | |342836,312237\0 | data section | 350803\0312237\0 | | | / | |---------------------| | etc | | ---------------------- |b will point to the constant in your program's data area after the b="212237"; instruction | ---------------------- | | b as a pointer | ---|-- ---------------------- | | this pointer will be after the char * b = new char[1024]; instruction ---------------------- | | 1024 bytes space |<---- ---------------------- The correct way to do the same: char* b = new char[1024]; // create a 1024 char long variable (or just: char b[1024];) strcpy(b,"312237"); // fill the first 7 characterw with "312237\0" strcat(b,",350803"); // copy the new string AFTER the previous one - the content will be: "312237,350803\0"; HTH -- Andras "It's MY computer" (tm Steve Gibson) andrasFeb 17, 2003, 3:16pm
[View Quote]
Only if your bot is running as an admin client. Considering your experience I don't advise you to try it too soon.
-- Andras "It's MY computer" (tm Steve Gibson) ananasFeb 17, 2003, 4:42pm
.... and 2 optimisation suggestions :
void handle_avatar_add (void) { int session; session = aw_int(AW_AVATAR_SESSION); switch (aw_int (AW_AVATAR_CITIZEN)) { // Saves some space to have the constant only once case CIT_Cameron999: case CIT_NelXaga: case CIT_SuperGuy3: case CIT_TSAAgent1: case CIT_DSdarkknight: case CIT_Ssl: case CIT_Aeo: case CIT_Reaper: case CIT_Duo: aw_whisper (session,"Whisper password to gain rights"); break; } } void handle_chat () { int session; session = aw_int(AW_CHAT_SESSION); char *ChatMsg; ChatMsg = strdup (aw_string(AW_CHAT_MESSAGE)); switch (aw_int (AW_AVATAR_CITIZEN)) { // shortened and much faster as you have only the one relevant strcmp case CIT_Cameron999 : Cameron999 = !strcmp (ChatMsg, "¶La®ge Stinky Gorillas Basking In The Sun¶"); break; case CIT_NelXaga : NelXaga = !strcmp (ChatMsg, "¶Nøøb Hater¶"); break; .... and so on ... default : free (ChatMsg); return; } free (ChatMsg); ProcessRights(); } baron sweetmanFeb 17, 2003, 9:29pm
Sorry i really didnt want to mix in to this, but hardcoding citnames? At
least read in the references from a file, sheesh for (int i=0,j=0;i<readfile("whatever.txt");i++) if (check_avnumber(i)) aw_whisper_session("Whisper password to gain rights"); else if(check_password(j=aw_int(AW_AVATAR_SESSION))) processrights(j); "ananas" <vha at oct31.de> wrote in news:3E512C51.213121E1 at oct31.de: why use strdup? ChatMsg = strdup (aw_string(AW_CHAT_MESSAGE)); Chatmsg = (char*)aw_string(AW_CHAT_MESSAGE); saves memory allocation bowenFeb 17, 2003, 9:54pm
[View Quote]
If you really want to use citnames, put the citnumbers in a file and then use
aw_citizen_attributes_by_number (int citizen) to get their citname. Would be a little harder, but in the end it's a lot more flexable. Especially if you happen to be having those tedious name changers. --Bown-- .duo.Feb 17, 2003, 10:37pm
I removed the checking of citnames from teh bot, there was just no point.
I'm just using them as variables. Its only a temporary bot anyway, I'm makng an advanced rightsbot in VB which will take a while to program. I guess I'm kind of rusty at programming, I learned VB programming in 1999 and C++ in 2000. I rarely program. Why should I use a file? What difference does it make, more easily edited? Its also less secure... but its what I'm going to do in my VB RightsBot, so I don't even know why I'm saying this crap, heh heh heh. [View Quote] .duo.Feb 17, 2003, 10:42pm
The thing is, I'm building an RPG and terrain comes out much better
hand-done than demeter-done. I want to have security as well as quality >_< so I don't have time to gain experience with it, could someone just write the code (according to my bot) for it? If its not too much trouble that is. [View Quote] bowenFeb 17, 2003, 11:06pm
[View Quote]
How is a file less secure than a built in variable? As long as you're hosting it,
there's no worries. --Bowen-- bowenFeb 18, 2003, 2:13pm
ananasFeb 19, 2003, 5:57pm
baron sweetmanFeb 19, 2003, 6:36pm
Ment to answer to the original post not to you Pineapple :)
"ananas" <vha at oct31.de> wrote in news:3E53E114.E069AF51 at oct31.de: > Wrong post to answer to, I just commented on the coding style, > not on the concepts. > |