Server Help

ASSS Custom Projects - ASSS Bot Core

Helicon - Wed Apr 02, 2003 10:30 pm
Post subject: ASSS Bot Core
any plans...?
Mine GO BOOM - Wed Apr 02, 2003 10:34 pm
Post subject:
Bot core? Most bots are just text based online, so all you really need is to see how the player commands work and do it that way. If you want visual bot as a player, there is the fake player module you can use.
SOS - Wed Apr 02, 2003 10:35 pm
Post subject:
On what?
ASSS itself pretty much can do the job of bots for you. It can even do some things that bots would not be able to.
Helicon - Wed Apr 02, 2003 10:35 pm
Post subject:
right-o, but one that comes canned, so normal people can write plugins in 10 minutes like with MERV (im whining!)
Mine GO BOOM - Wed Apr 02, 2003 10:42 pm
Post subject:
10 minute plugins arn't always good. They are more likely to not be well planned, and are more likely to crash and burn than one you spent time on making.

And doing a 10-minute edit to add some new commands for what you need to an existing file is still simple to do.
Helicon - Wed Apr 02, 2003 10:43 pm
Post subject:
10 to 1 the bot that anyone needs is available in component parts stolen from others, or based on previous bots written
Dr Brain - Wed Apr 02, 2003 10:46 pm
Post subject:
Bots may offer an advantage (for now) for the average joe zone sysop, but for the power sysop (biggrin.gif) ASSS offers many advantages. When V1 is released, expect to see a sudden lack of bots in some zones.
Helicon - Wed Apr 02, 2003 10:59 pm
Post subject:
no kidding, esp the big zones.
SOS - Thu Apr 03, 2003 7:56 am
Post subject:
If only ASSS would not be in damn C icon_sad.gif icon_sad.gif icon_sad.gif
Anonymous - Thu Apr 03, 2003 10:38 am
Post subject:
no kidding, no classes, just structs? kinda behind the curve, eh? i saw the Grem quote on the other board... i think he thought himself in circles... we can write dlls in c++ though? or even (*eeek!) declare functions in VB. That will be nice. thats why i think a core would be nice... so those of us who are used to comprehending data and functions as a single unit won't get lost in the arrays and linked lists icon_smile.gif
Mine GO BOOM - Thu Apr 03, 2003 5:54 pm
Post subject:
It was written in C because when he started it in C++, it started to get very unorganized. Its somewhere in his source-release. That, or maybe its only on his server, but i read it somewhere. Anyways, its looking good as C now, no reason to convert over.

As for the C++: I was going to put a hack on the server for the Win32 build for it to read C++ dll's without problems. MSVC likes to add _ and @#'s to things when exporting a function as "C". As for VB, i never had to read a VB dll before, so never looked at the function's exported name.
Helicon - Thu Apr 03, 2003 6:14 pm
Post subject:
could you post something to get my started? i want to work this thing, but im quite honestly flabbergasted (i never bothered with C, just went to C++, which was taught at school, any escuse? no).

How exactly would i build a dll module to do something when a player changes chip, like spit something to chat.

just something very simple. not even necessarily that event. anything really. ive lost my feet, if you can get me up ill be glad to start chugging out code icon_razz.gif
Mine GO BOOM - Thu Apr 03, 2003 6:44 pm
Post subject:
Code: Show/Hide
#include <stdlib.h>
#include <stdio.h>
#include "asss.h"
/* standard includes */

local Ichat *chat; /* required so you can do the chat->SendArenaMessage */
local Imodman *mm; /* just to keep the same design as other modules */

void TellShipChange(Player *p, int newship, int newfreq)
/* this function is of the same type as [b]ShipChangeFunc[/b] is defined
* in game.h
*/
{
   /* SendArenaMessage requires a pointer to the arena info
    * (which Player data contains as p->arena), then the text you want
    */
   chat->SendArenaMessage(p->arena, "Player %s changed to ship %d on freq %d", p->name, newship, newfreq);
}

EXPORT int MM_shiptell(int action, Imodman *_mm, Arena *arena)
/* the ONLY thing you need to ever change in EXPORT function is the part
* after the MM_. The MM_ is required, but after it is free game (no spaces,
* as usual for functions
*/
{
   if (action == MM_LOAD)
   {
      /* MM_LOAD is the action whenever the dll is first started
       * up. This is where you load in other interfaces and setup
       * any initial values
       */

      mm = _mm;

      chat = mm->GetInterface(I_CHAT, ALLARENAS);
      /* this will let us use the chat interface */

      if (!chat) return MM_FAIL;
      /* make sure this dll is loaded after the chat dll is, since
       * our code assumes that [b]chat[/b] is always a valid pointer
       */

      mm->RegCallback(CB_SHIPCHANGE, TellShipChange, ALLARENAS);
      /* a RegCallback sets up a function to be called whenever
       * the action you request is done. In game.h, you can see
       * the CB_SHIPCHANGE callback, so we setup a function
       * to use it.
       */

      return MM_OK;
   }
   else if (action == MM_UNLOAD)
   /* MM_UNLOAD happens right before your dll is about to be
    * free'd, so now is the time to dealloc memory and
    * unregister any interfaces/callbacks we have so the server
    * won't crash after we leave. Do [b]NOT[/b] assume the server
    * is shutting down if you get this!
    */
   {
      /* Just undoing what we did in MM_LOAD */
      mm->UnregCallback(CB_SHIPCHANGE, TellShipChange, ALLARENAS);

      mm->ReleaseInterface(chat);
      return MM_OK;
   }
   return MM_FAIL;
}


I typed this all up at school, so there might be a compile error or misspelling somewhere in there. Anyways, that should do what you wanted, sends pretty much a *arena whenever someone changes ships.
Helicon - Thu Apr 03, 2003 9:31 pm
Post subject:
thank you mucho, these function pointer nonsenses are killing me...
Helicon - Thu Apr 03, 2003 9:36 pm
Post subject:
GetInterface returns void, cannot assign to Ichat

Code: Show/Hide

chat = mm->GetInterface(I_CHAT, ALLARENAS);


DOH! IT STILL THINKS IM A C++ JUNKY!
Helicon - Thu Apr 03, 2003 9:56 pm
Post subject:
just checking can i Register multiple callbacks to a single interface (it compiles ok)

IE
Code: Show/Hide

mm->RegCallback(CB_SHIPCHANGE, onShipChange, ALLARENAS);     mm->RegCallback(CB_FREQCHANGE,onFreqChange,ALLARENAS);
mm->RegCallback(CB_KILL,onKill,ALLARENAS);


PS Is there a player ship movement callback to register? i searched, to no avail
Helicon - Thu Apr 03, 2003 11:06 pm
Post subject:
see anything wrong with this? compiles 100% error and warning free.

NOTE: this was quick code, please dont make any comments like "dirty" or "unfinished"
Code: Show/Hide

// helicon.cpp : Defines the entry point for the DLL application.
//

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "asss.h"

//// GLOBAL VARS ////
local Ichat *chat;
local Imodman *mm;
/////////////////////


/*    EVENT HANDLER PROTOTYPES    *\
        (call these anywhere)
\*                           */
   void onArenaAction(Arena *a, int action);
   void onFlagWin(Arena *arena, int freq);
   void onFlagPos(Arena *arena, int fid, int x, int y, int freq);
   void onFlagDrop(Arena *arena, Player *p, int count, int neut);
   void onPlayerAction(Player *p, int action, Arena *arena);
   void onGoal(Arena *arena, Player *p, int bid, int x, int y);
   void onFlagPickup(Arena *arena, Player *p, int fid, int oldfreq, int carried);
   void onBallFire(Arena *arena, Player *p, int bid);

   void onBallPickup(Arena *arena, Player *p, int bid);
   void onKill(Arena *arena, Player *killer, Player *killed, int bounty, int flags);
   void onFreqChange(Player *p, int newfreq);
   void onShipChange(Player *p, int newship, int newfreq);
   void onChatMsg(Player *p, int type, Player *target, int freq, const char *text);
   int startup();

//// EVENT HANDLERS ////
void onChatMessage(Player *p, int type, Player *target, int freq, const char *text){
}
void onArenaAction(Arena *a, int action){
}
void onFlagWin(Arena *arena, int freq){
}
void onFlagPos(Arena *arena, int fid, int x, int y, int freq){
}
void onFlagDrop(Arena *arena, Player *p, int count, int neut){
}
void onPlayerAction(Player *p, int action, Arena *arena){
   switch(action){
   case PA_CONNECT:
      break;
   case PA_DISCONNECT:
      break;
   case PA_PREENTERARENA:
      break;
   case PA_ENTERARENA:
      break;
   case PA_LEAVEARENA:
      break;
   }
}
void onFlagPickup(Arena *arena, Player *p, int fid, int oldfreq, int carried){
}
void onGoal(Arena *arena, Player *p, int bid, int x, int y){
}
void onBallFire(Arena *arena, Player *p, int bid){
}
void onBallPickup(Arena *arena, Player *p, int bid){
}
void onKill(Arena *arena, Player *killer, Player *killed, int bounty, int flags){
}
void onFreqChange(Player *p, int newfreq){
}
void onShipChange(Player *p, int newship, int newfreq){
   chat->SendArenaMessage(p->arena, "Player %s changed to ship %d on freq %d", p->name, newship, newfreq);
}
int startup(){
//TODO:stick you initialization code here
   return 1;
}

/********************* MAIN DLL BODY ************************/
EXPORT int MM_botcore(int action, Imodman *mm_, Arena *arena){

   if (action == MM_LOAD){
      mm = mm_; //shorthand

//REGISTER INTERFACES
      chat = mm->GetInterface(I_CHAT, ALLARENAS);

//RUN STARTUP FUNCTION, KILL IF BAD RETURN
      if(!startup()) return MM_FAIL;

      if (!chat) return MM_FAIL;

//REGISTER CALLBACKS
      //game.h
         mm->RegCallback(CB_SHIPCHANGE, onShipChange, ALLARENAS);
         mm->RegCallback(CB_FREQCHANGE,onFreqChange,ALLARENAS);
         mm->RegCallback(CB_KILL,onKill,ALLARENAS);

      //balls.h
         mm->RegCallback(CB_BALLPICKUP,onBallPickup,ALLARENAS);
         mm->RegCallback(CB_BALLFIRE,onBallFire,ALLARENAS);
         mm->RegCallback(CB_GOAL,onGoal,ALLARENAS);

      //core.h
         mm->RegCallback(CB_PLAYERACTION, onPlayerAction, ALLARENAS);

      //flags.h
         mm->RegCallback(CB_FLAGPICKUP, onFlagPickup, ALLARENAS);
         mm->RegCallback(CB_FLAGDROP, onFlagDrop, ALLARENAS);
         mm->RegCallback(CB_FLAGPOS,onFlagPos,ALLARENAS);
         mm->RegCallback(CB_FLAGWIN,onFlagWin,ALLARENAS);

      //arena.h
         mm->RegCallback(CB_ARENAACTION, onArenaAction, ALLARENAS);
      
      //chat.h
         mm->RegCallback(CB_CHATMSG,onChatMessage,ALLARENAS);

   }
   else if (action == MM_UNLOAD){
//UNREGISTER THE CALLBACKS
         //game.h
         mm->UnregCallback(CB_SHIPCHANGE, onShipChange, ALLARENAS);
         mm->UnregCallback(CB_FREQCHANGE,onFreqChange,ALLARENAS);
         mm->UnregCallback(CB_KILL,onKill,ALLARENAS);

         //balls.h
         mm->UnregCallback(CB_BALLPICKUP,onBallPickup,ALLARENAS);
         mm->UnregCallback(CB_BALLFIRE,onBallFire,ALLARENAS);
         mm->UnregCallback(CB_GOAL,onGoal,ALLARENAS);

         mm->UnregCallback(CB_PLAYERACTION, onPlayerAction, ALLARENAS);

         //flags.h
         mm->UnregCallback(CB_FLAGPICKUP, onFlagPickup, ALLARENAS);
         mm->UnregCallback(CB_FLAGDROP, onFlagDrop, ALLARENAS);
         mm->UnregCallback(CB_FLAGPOS,onFlagPos,ALLARENAS);
         mm->UnregCallback(CB_FLAGWIN,onFlagWin,ALLARENAS);

         //arena.h
         mm->UnregCallback(CB_ARENAACTION, onArenaAction, ALLARENAS);

         //chat.h
         mm->UnregCallback(CB_CHATMSG,onChatMessage,ALLARENAS);

//RELEASE INTERFACES
         mm->ReleaseInterface(chat);
         return MM_OK;
      }

      return MM_FAIL; //problem
}

Mine GO BOOM - Fri Apr 04, 2003 12:39 am
Post subject:
Try renaming the file to .c instead of .cpp. That way it will compile as a C program, instead of MSVC trying to C++-ify the exported function.
Gravitron - Fri Apr 04, 2003 3:20 am
Post subject:
Shouldn't this be moved onto one of them coding forums?
Helicon - Fri Apr 04, 2003 12:30 pm
Post subject:
yeah probably... btw it is a .c file, but MSVC++ is a bitch.
still no luck with a "PlayerMove-esque" callback?

maybe there is a call to retrieve current Player structs?
Grelminar - Fri Apr 04, 2003 7:40 pm
Post subject: reply to lots of posts here
Bot core: bots are dumb. Write modules instead. Yes, there are plans for an easy-to-use way of writing modules and other stuff. They're just plans for now, because I have higher priorities and very limited time. For now, you'll have to use C or get someone to do it for you. If you have ideas that you think would make generally useful modules (i.e., useful to more than just one zone), tell me and I might do them myself.

Why C? I don't like C++ (yes, I do have good reasons for this), and I wasn't comfortable enough with any alternative languages at the time when I started. As I've said elsewhere, the perfect language for an SS server is probably Erlang. If I add a supported extension language, it'll probably be Python, because it's simple, easy to learn, and unobjectionable.

It's hard to learn: Yeah, I know. It's a big complicated mess of event-driven multi-threaded code with many interacting modules. Sorry, that's just how it has to be to do its job. Some developer documentation would help, but I haven't had a chance yet. Btw, I _don't_ think adding comments to .c files will help at all. It's the header files that need comments, to describe what each function in each interface does, and when each callback is called. And then something spelling out how to use interfaces, callbacks, and what happens in which thread.

In C, not C++, void pointers are automatically coerced to any pointer type.

You can register as many callbacks as you want in a module.

There is no ship movement callback, for efficiency reasons: it would get called far too often. You can access current player position information from the player structure (p->position.x,y,etc.). In the future there will probably be callback events for entering and exiting user-defined regions.

That code (in msg Thu Apr 03, 2003 11:06 pm) looks fine. Realize that you'll need to get pointers to a bunch more interfaces than chat if you want to do anything useful. Also realize that registering lots of callbacks that don't do anything will make things slower (though it probably won't be a big deal). Finally, if you're writing a module that's going to apply to specific arenas, then you probably want to set up your callbacks in the MM_ATTACH event (and unreg them in MM_DETACH), and pass in the arena pointer instead of ALLARENAS, so that it will only be called for events in that arena.
Anonymous - Fri Apr 04, 2003 10:44 pm
Post subject:
thank you for your support. i am duly grateful for your work, it is truly outstanding, but, as a certified bitcher, this is my job. i cam currently writing my own stuff (digging out the C, damn i thought i'd never use those libraries!) I understand the need for more interfaces, ive got them. I also understand my liberal use of the word "bot" may not have been the best given the situation. i suppose "mod_bot" would have been more appropriate, eh?

right now im just making a really friggin huge module with "bot-esque"(word?) format to learn your API, relearn C, and offer myslef a mod-able(word?) template for making simple game hacks and pseudo-bot game-specific modules. ill let you know if i accidentally come up with something good.

hopefully the end of all this will be an extension of the .conf and .cfg structure to support common game types with greater ease, IE infantry, flaggin, etc
Anonymous - Fri Apr 04, 2003 10:47 pm
Post subject:
PS, i think i might actually finish a VB program to spit out .c files with only chosen callbacks and interfaces done automatically...interested? probably not, but it will certainly save me some time.

inn your estimation, how much do you believe the callbacks and interfaces will have changed come (blessed) release?
Anonymous - Fri Apr 04, 2003 11:03 pm
Post subject:
using mainloop->SetTimer
and using FOR_EACH_PLAYER(p) to iterate would be feasible?
Anonymous - Fri Apr 04, 2003 11:33 pm
Post subject:
one last thing for tonight:

in your example (MGB) you provided something to this effect;
Code: Show/Hide

void onShipChange(Player *p, int newship, int newfreq){
   //chat->SendArenaMessage(p->arena, "Player %s changed to ship %d on freq %d", p->name, newship, newfreq);
}


utilizing the Ichat function:
Code: Show/Hide

void (*SendArenaMessage)(Arena *arena, const char *format, ...);


the %s and (2) %d (which appear different when printed in-game), as well as you passing the parameters to the function, produce a nice result that would certainly circumvent some CString confusion

could you please explain their use? are they flexible?
Helicon - Sat Apr 05, 2003 1:45 pm
Post subject:
Code: Show/Hide

//// chat.c ////
local void SendArenaMessage(Arena *arena, const char *str, ...)
{
   LinkedList set = LL_INITIALIZER;
   va_list args;

   get_arena_set(&set, arena);

   va_start(args, str);
   v_send_msg(&set, MSG_ARENA, 0, str, args);
   va_end(args);
}



my C is rusty, here is the function...please explain the

Code: Show/Hide

...){


argument
Dr Brain - Sat Apr 05, 2003 2:25 pm
Post subject:
its the etc... means you put the rest in there, he didnt have time to write it all in.
Helicon - Sat Apr 05, 2003 6:39 pm
Post subject:
no its in the function decalration... in the code...that is not a comment in chat.c
Mine GO BOOM - Sun Apr 06, 2003 1:52 am
Post subject:
... means "anything". Have you never used printf before? Anyways, it works like this. The function inside reads the normal variables that are defined, then reads the argument list for the extra stuff. It does a little bit of work, exchanging %s, %d, etc, in a string (usually one of the variables passed to the function) with the extra stuff you sent it. Play around with a printf once to get the hang of it.
Helicon - Sun Apr 06, 2003 12:35 pm
Post subject:
like i said...i quite a bit rusty....

i messed with it... do %s and %d have any other equivalents as in a possible %a. i noticed you pass p->name and use %s while integers like newship are alll %d
Mine GO BOOM - Sun Apr 06, 2003 1:53 pm
Post subject:
Check out MSDN every so often with your coding requirements:

Format Specification Fields: printf and wprintf Functions
Warhaven - Thu Oct 02, 2003 7:54 pm
Post subject: It's bad enough...
... that Continuum is written in VB.

It could respond SO much better if done in C++.

I even offered to do a port (which would have included a Cocoa version), but they replied, "We don't see a market for it."

I just want to know what market they're speaking of. It's not like Continuum makes money.
Mine GO BOOM - Thu Oct 02, 2003 8:57 pm
Post subject: Re: It's bad enough...
Warhaven wrote:
Continuum is written in VB


I believe you are mistaken here. Continuum is done in C++, the whole way throughout. I don't know where you got the VB part, but it is wrong. Trust me, Priit hates VB as much as the next guy.

And who would respond to a question with the "market" answer? I would have thought your post would be about something else completely, but you did mention Continuum.
Warhaven - Wed Oct 08, 2003 6:20 pm
Post subject: My Mistake
The earlier versions of Continuum weren't very responsive, and I was told by several people online that it was written in VB (which would have explained everything, outside of it being an early release).

Might explain a little why I got scuffed off. Sorry. tongue.gif

In any event, I had mentioned helping to do a port for OS X (macintosh), and the response was, "We don't see a market for it." So I was wondering what market he/she/they were talking about. May have been a retort against the VB remark.

Anyway, I have a feeling they're not too keen with the PPC architecture, Macs in particular. I get a lot of anti-Mac sentiments in the SS community, so a port is probably very unlikely, even if offered the help.
Dustpuppy - Thu Oct 09, 2003 9:35 am
Post subject:
Looks like standard printf() formatting...
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group