Server Help

ASSS Custom Projects - Teamkill module

Helicon - Tue Apr 15, 2003 5:14 pm
Post subject: Teamkill module
This is not only simplistic, and nerely useless, but if someone could tear it to pieces, i might learn something...

Code: Show/Hide

/******************* TEAMKILL REFEREE ******************************\
   Checks all arenas for teamkilling.
   Responds with configured chat messages in .conf

   [Teamkill]
   KillerChatResponse = <string>
      ;sent to teamkiller in chat
   VictimChatResponse = <string>
      ;same for the victim
   WarpVictim = <bool 1|0>
      ;if 1, will warp the victim back to their position
   WarpKiler = <bool 1|0>
      ;if 1, will set killer to ship 1 (or 2 if they are in a warbird)

   Obviously, many more options will become available as billing support comes online
\*******************************************************************/

//// INCLUDES ////
#include "asss.h"

////// GLOBAL VARS ///////
local Ichat *chat;
local Imodman *mm;
local Iconfig *cfg;
local Igame *game;

//// EVENT HANDLERS ////
void onChatMessage(Player *p, int type, Player *target, int freq, const char *text){
   
}
void onKill(Arena *arena, Player *killer, Player *killed, int bounty, int flags){
   //check for teamkill
   if (killer->p_freq == killed->p_freq){

      //message killer
      chat->SendMessage(killer,cfg->GetStr(GLOBAL,"Teamkill","KillerChatResponse"));

      //change killer ship to Warbird
      if(cfg->GetInt(GLOBAL,"Teamkill","WarpKiller",0) == 1){
         if(killer->p_ship == WARBIRD){ //already in warbird, send to Jav
            game->SetShip(killer,JAVELIN);
         }
         else{ //send to Warbird
            game->SetShip(killer, WARBIRD);
         }
      }

      //message victim
      chat->SendMessage(killed,cfg->GetStr(GLOBAL,"Teamkill","VictimChatResponse"));

      //warp victim?
      if(cfg->GetInt(GLOBAL,"Teamkill","WarpVictim",0) == 1){
         
         //build target struct, thanks Smong!
         Target t;
         t.type = T_PLAYER;
         t.u.p = killed;
         game->WarpTo(&t, killed->position.x, killed->position.y);
         
      }
   }
}

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

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

      chat   = mm->GetInterface(I_CHAT, ALLARENAS);
      cfg      = mm->GetInterface(I_CONFIG,ALLARENAS);
      game   = mm->GetInterface(I_GAME,ALLARENAS);

      if(!chat)      return MM_FAIL;
      
      //game.h

         mm->RegCallback(CB_KILL,onKill,ALLARENAS);
      
      //chat.h
         mm->RegCallback(CB_CHATMSG,onChatMessage,ALLARENAS);
         return MM_OK;

   }
   else if (action == MM_UNLOAD){
         //game.h
         mm->UnregCallback(CB_KILL,onKill,ALLARENAS);

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

         mm->ReleaseInterface(chat);
         mm->ReleaseInterface(cfg);
         mm->ReleaseInterface(game);

         return MM_OK;
   }

   return MM_FAIL;
}


Perhpas this is very much workable through editing the game itself... this dawns on me now... so difficult thinking not in terms of circumventing, but working throgh now.
Offhand Question: Any new release news?
Grelminar - Wed Apr 16, 2003 2:54 am
Post subject:
Not too bad. A few things I'd change:

Don't pass the result of a cfg->GetStr right into something else. That will return NULL if the requested setting doesn't exist. So assign it to a variable and check it first.

Don't pass non-constant strings as the format parameter in a SendMessage, or Log, or any other function that passes arguments to printf. That leaves you wide open to format string attacks (imagine what happens when someone puts a %s in that config setting). Always use "%s" as the format string, and the text from the config file as the first extra parameter.

Don't use GLOBAL for the config file, because you want to be able to customize this per-arena. Use arena->cfg.

To warp someone, give them the warp prize with game->GivePrize.

I think there's a chance that the position.x,y will reflect the new spawn position rather than the position before the kill, depending on the order the packets come in. If there's a spawn delay it should always work, but I'm not sure if it'll be reliable enough if there isn't.
Helicon - Wed Apr 16, 2003 4:07 pm
Post subject:
...thanks, ill post an update later
Smong - Thu Apr 17, 2003 5:35 pm
Post subject:
Attached is the source for my upgraded version of Helicon's teamkill module (even though they called it modbot). You need to compile it with util.c and link pthread.lib (which makes it about 20k bigger).

This version of teamkill either spec's the tk'er or warps them to a penalty box and then repeatedly depletes energy for a set time. Settings are per arena and the tk message is now red. I took the liberty of adding some appropriate(?) sounds.

Commands:
*tkunlock <optional message> - Incase they were wrongly accused
*tkstats or ?tkstats <case-sensitive-name> - how mnay tk's since detected
?tkclear - wipe the internal list of tk'ers
*tktest - make it look like someone tk'd you

.conf:
[Teamkill]
KillerMessage=Canniball! (If you are absolutely sure you didn't TK, log out then back in again)
VictimMessage=Notice anything strange lately?
PenaltyTime=15
Action=2
;0 = no action
;1 = spec
;2 = warp (see below)
WarpX=553
WarpY=512

And here's a compiler warning:
Quote:


118 C:\Dev-Cpp\Examples\asss-20030327\ref_teamkill.c
[Warning] assignment discards qualifiers from pointer target type

Code: Show/Hide

109:   char *KillerChatResponse;
117:   KillerChatResponse = cfg->GetStr(killer->arena->cfg, "Teamkill",
118:      "KillerChatResponse");

Helicon - Thu Apr 17, 2003 5:45 pm
Post subject:
i feel owned. 'Cept for that compile error new_evil.gif
Mine GO BOOM - Thu Apr 17, 2003 5:49 pm
Post subject:
Try this:

Code: Show/Hide
const char *KillerChatResponse;


Since GetStr returns a const char*, i'll assume thats the warning its giving you.
Helicon - Thu Apr 17, 2003 9:37 pm
Post subject:
wouldnt there be a way to deny teamkills(yeah, opposite of my other thread) via the packets? could one do it without calculating the damage vs energy?
Dr Brain - Fri Apr 18, 2003 10:04 am
Post subject:
Not without calculating which bombs will team kill.
Helicon - Fri Apr 18, 2003 2:15 pm
Post subject:
i thought not
Smong - Fri Apr 18, 2003 3:20 pm
Post subject:
Don't worry Helicon, I've left some stuff for you to do biggrin.gif . Player's entering and leaving need to be handled, mainly because their Player *p might change causing the module to send an energy deplete prize or ship change to an invalid pointer icon_exclaim.gif . The only reason I haven't done this is because last time I had an onPlayerAction() callback Asss crashed on me icon_cry.gif .
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group