/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/command.c
ViewVC logotype

Diff of /pvpgn-1.7.4/src/bnetd/command.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1.1.1 by sysadm, Tue Jun 6 03:41:37 2006 UTC Revision 1.3 by sysadm, Sat Jun 24 12:31:37 2006 UTC
# Line 107  Line 107 
107  #include "clan.h"  #include "clan.h"
108  #include "common/setup_after.h"  #include "common/setup_after.h"
109    
110    #ifndef CHAR_STATUS_DUMP_FILE
111    # define CHAR_STATUS_DUMP_FILE       "/tmp/d2charstatus.dat"
112    #endif
113    
114  static char const * bnclass_get_str(unsigned int class);  static char const * bnclass_get_str(unsigned int class);
115  static void do_whisper(t_connection * user_c, char const * dest, char const * text);  static void do_whisper(t_connection * user_c, char const * dest, char const * text);
# Line 337  static int _handle_unwatchall_command(t_ Line 340  static int _handle_unwatchall_command(t_
340  static int _handle_lusers_command(t_connection * c, char const * text);  static int _handle_lusers_command(t_connection * c, char const * text);
341  static int _handle_news_command(t_connection * c, char const * text);  static int _handle_news_command(t_connection * c, char const * text);
342  static int _handle_games_command(t_connection * c, char const * text);  static int _handle_games_command(t_connection * c, char const * text);
343    static int _handle_games_ext_command(t_connection * c, char const * text);
344  static int _handle_channels_command(t_connection * c, char const * text);  static int _handle_channels_command(t_connection * c, char const * text);
345  static int _handle_addacct_command(t_connection * c, char const * text);  static int _handle_addacct_command(t_connection * c, char const * text);
346  static int _handle_chpass_command(t_connection * c, char const * text);  static int _handle_chpass_command(t_connection * c, char const * text);
# Line 369  static int _handle_commandgroups_command Line 373  static int _handle_commandgroups_command
373  static int _handle_topic_command(t_connection * c, char const * text);  static int _handle_topic_command(t_connection * c, char const * text);
374  static int _handle_moderate_command(t_connection * c, char const * text);  static int _handle_moderate_command(t_connection * c, char const * text);
375  static int _handle_clearstats_command(t_connection * c, char const * text);  static int _handle_clearstats_command(t_connection * c, char const * text);
376    static int _handle_char_status_command(t_connection * c, char const *text);
377    
378  static const t_command_table_row standard_command_table[] =  static const t_command_table_row standard_command_table[] =
379  {  {
# Line 414  static const t_command_table_row standar Line 419  static const t_command_table_row standar
419          { "/kick"               , _handle_kick_command },          { "/kick"               , _handle_kick_command },
420          { "/ban"                , _handle_ban_command },          { "/ban"                , _handle_ban_command },
421          { "/unban"              , _handle_unban_command },          { "/unban"              , _handle_unban_command },
422            { "/charstatus"        , _handle_char_status_command },
423    
424          { NULL                  , NULL }          { NULL                  , NULL }
425                    
# Line 432  static const t_command_table_row extende Line 438  static const t_command_table_row extende
438          { "/lusers"             , _handle_lusers_command },          { "/lusers"             , _handle_lusers_command },
439          { "/news"               , _handle_news_command },          { "/news"               , _handle_news_command },
440          { "/games"              , _handle_games_command },          { "/games"              , _handle_games_command },
441            { "/games_ext"          , _handle_games_ext_command },
442          { "/channels"           , _handle_channels_command },          { "/channels"           , _handle_channels_command },
443          { "/chs"                , _handle_channels_command },          { "/chs"                , _handle_channels_command },
444          { "/addacct"            , _handle_addacct_command },          { "/addacct"            , _handle_addacct_command },
# Line 2747  static int _glist_cb(t_game *game, void Line 2754  static int _glist_cb(t_game *game, void
2754  {  {
2755      struct glist_cb_struct *cbdata = (struct glist_cb_struct*)data;      struct glist_cb_struct *cbdata = (struct glist_cb_struct*)data;
2756    
2757            // Skip void game
2758            if (game_get_ref(game) == 0)
2759                    return 0;
2760            
2761      if ((!cbdata->tag || !prefs_get_hide_pass_games() || game_get_flag(game) != game_flag_private) &&      if ((!cbdata->tag || !prefs_get_hide_pass_games() || game_get_flag(game) != game_flag_private) &&
2762          (!cbdata->tag || game_get_clienttag(game)==cbdata->tag) &&          (!cbdata->tag || game_get_clienttag(game)==cbdata->tag) &&
2763          (cbdata->diff==game_difficulty_none || game_get_difficulty(game)==cbdata->diff))          (cbdata->diff==game_difficulty_none || game_get_difficulty(game)==cbdata->diff))
# Line 4639  static int _handle_clearstats_command(t_ Line 4650  static int _handle_clearstats_command(t_
4650    
4651      return 0;      return 0;
4652  }  }
4653    
4654    static int _glist_cb_ext(t_game *game, void *data)
4655    {
4656            t_connection * owner_conn = NULL;
4657            t_account * owner_account = NULL;
4658            const char * owner_email = NULL;
4659    
4660        struct glist_cb_struct *cbdata = (struct glist_cb_struct*)data;
4661    
4662            // Skip void game
4663            if (game_get_ref(game) == 0)
4664                    return 0;
4665                    
4666            if (owner_conn = game_get_owner(game)) {
4667                    if (owner_account = conn_get_account(owner_conn)) {
4668                            owner_email = account_get_email(owner_account);
4669                    }
4670            }
4671    
4672            sprintf(msgtemp," %-16.16s %-16.16s %1.1s %-8.8s %-21.21s %5u %-16.16s %-25.25s",
4673                game_get_name(game),
4674                game_get_pass(game),
4675                game_get_flag(game) != game_flag_private ? "n":"y",
4676                game_status_get_str(game_get_status(game)),
4677                game_type_get_str(game_get_type(game)),
4678                game_get_ref(game),
4679                account_get_name(owner_account),
4680                owner_email ? owner_email : "Unknown");
4681    
4682            if (!cbdata->tag)
4683            {
4684            
4685              strcat(msgtemp,clienttag_uint_to_str(game_get_clienttag(game)));
4686              strcat(msgtemp," ");
4687            }
4688                
4689            strcat(msgtemp, addr_num_to_addr_str(game_get_addr(game),game_get_port(game)));
4690                
4691            message_send_text(cbdata->c,message_type_info,cbdata->c,msgtemp);
4692    
4693        return 0;
4694    }
4695    
4696    static int _handle_games_ext_command(t_connection * c, char const *text)
4697    {
4698      unsigned int   i;
4699      unsigned int   j;
4700      char           clienttag_str[5];
4701      char           dest[5];
4702      struct glist_cb_struct cbdata;
4703    
4704      for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */
4705      for (; text[i]==' '; i++);
4706      for (j=0; text[i]!=' ' && text[i]!='\0'; i++) /* get dest */
4707        if (j<sizeof(dest)-1) dest[j++] = text[i];
4708      dest[j] = '\0';
4709      for (; text[i]==' '; i++);
4710    
4711      cbdata.c = c;
4712    
4713      if(strcmp(&text[i],"norm")==0)
4714        cbdata.diff = game_difficulty_normal;
4715      else if(strcmp(&text[i],"night")==0)
4716        cbdata.diff = game_difficulty_nightmare;
4717      else if(strcmp(&text[i],"hell")==0)
4718        cbdata.diff = game_difficulty_hell;
4719      else
4720        cbdata.diff = game_difficulty_none;
4721      
4722      if (dest[0]=='\0')
4723        {
4724          cbdata.tag = conn_get_clienttag(c);
4725          message_send_text(c,message_type_info,c,"Currently running games:");
4726        }
4727      else if (strcasecmp(&dest[0],"all")==0)
4728        {
4729          cbdata.tag = 0;
4730          message_send_text(c,message_type_info,c,"All current games:");
4731        }
4732      else
4733        {
4734          cbdata.tag = tag_case_str_to_uint(&dest[0]);
4735    
4736          if (!tag_check_client(cbdata.tag))
4737          {
4738            message_send_text(c,message_type_error,c,"No valid clienttag specified.");
4739            return -1;
4740          }
4741          
4742          if(cbdata.diff==game_difficulty_none)
4743            sprintf(msgtemp,"Current games of type %s",tag_uint_to_str(clienttag_str,cbdata.tag));
4744          else
4745            sprintf(msgtemp,"Current games of type %s %s",tag_uint_to_str(clienttag_str,cbdata.tag),&text[i]);
4746          message_send_text(c,message_type_info,c,msgtemp);
4747        }
4748      
4749      sprintf(msgtemp," ------name------ ------pass------ p -status- --------type--------- count ---owner name--- --------owner email------- ");
4750      if (!cbdata.tag)
4751        strcat(msgtemp,"ctag ");
4752      strcat(msgtemp,"--------addr--------");
4753      message_send_text(c,message_type_info,c,msgtemp);
4754      gamelist_traverse(_glist_cb_ext,&cbdata);
4755    
4756      return 0;
4757    }
4758    
4759    static int _handle_char_status_command(t_connection * c, char const *text)
4760    {
4761            FILE * fp;
4762            
4763            if (!(fp = fopen(CHAR_STATUS_DUMP_FILE, "r"))) {
4764                    eventlog(eventlog_level_error, __FUNCTION__, "Can't read char status file %s", CHAR_STATUS_DUMP_FILE);
4765                    sprintf(msgtemp,"Can't read char status file.");
4766                    message_send_text(c,message_type_info,c,msgtemp);
4767            } else {
4768                    while (fgets(msgtemp, MAX_MESSAGE_LEN, fp)) {
4769                            msgtemp[strlen(msgtemp) - 1] = '\0';
4770                            message_send_text(c,message_type_info,c,msgtemp);
4771                    }
4772                    fclose(fp);
4773            }
4774    
4775            return 0;
4776    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1