Skip to forum content

You are not logged in. Please login or register.


forums.pvpgn.pro → [EN] The Source Code → how to merge commands ?

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 10

1

Topic: how to merge commands ?

how to merge 3 commands in 1 ?
so if i type /ptc
it will show /p, /time, /channel

this is my /p source code

static int _handle_ping_command(t_connection * c, char const *text)
{
  unsigned int i;
  t_connection *    user;
  t_game     *    game;

  for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */
  for (; text[i]==' '; i++);

  if (text[i]=='\0')
    {
      if ((game=conn_get_game(c)))
    {
      for (i=0; i<game_get_count(game); i++)
        {
          if ((user = game_get_player_conn(game, i)))
        {
          snprintf(msgtemp, sizeof(msgtemp), "%.64s latency: %9u",conn_get_username(user),conn_get_latency(user));
          message_send_text(c,message_type_info,c,msgtemp);
        }
        }
      return 0;
    }
      snprintf(msgtemp, sizeof(msgtemp), "Your latency %9u",conn_get_latency(c));
    }
  else if ((user = connlist_find_connection_by_accountname(&text[i])))
    snprintf(msgtemp, sizeof(msgtemp), "%.64s latency %9u",&text[i],conn_get_latency(user));
  else
    snprintf(msgtemp, sizeof(msgtemp), "Invalid user");

  message_send_text(c,message_type_info,c,msgtemp);
  return 0;
}

this is my /time source code:

static int _handle_time_command(t_connection * c, char const *text)
{
  t_bnettime  btsystem;
  t_bnettime  btlocal;
  std::time_t      now;
  struct std::tm * tmnow;

  btsystem = bnettime();

  /* Battle.net time: Wed Jun 23 15:15:29 */
  btlocal = bnettime_add_tzbias(btsystem,local_tzbias());
  now = bnettime_to_time(btlocal);
  if (!(tmnow = std::gmtime(&now)))
    std::strcpy(msgtemp,"Waktu server BrandGamers: ?");
  else
    std::strftime(msgtemp,sizeof(msgtemp),"Waktu server BrandGamers: %a %b %d %H:%M:%S",tmnow);
  message_send_text(c,message_type_info,c,msgtemp);
  if (conn_get_class(c)==conn_class_bnet)
    {
      btlocal = bnettime_add_tzbias(btsystem,conn_get_tzbias(c));
      now = bnettime_to_time(btlocal);
      if (!(tmnow = std::gmtime(&now)))
    std::strcpy(msgtemp,"Waktu lokalmu: ?");
      else
    std::strftime(msgtemp,sizeof(msgtemp),"Waktu lokalmu: %a %b %d %H:%M:%S",tmnow);
      message_send_text(c,message_type_info,c,msgtemp);
    }

  return 0;
}

this is my /channel source code:

static int _handle_channels_command(t_connection * c, char const *text)
{
  unsigned int      i;
  t_elem const *    curr;
  t_channel const * channel;
  t_clienttag       clienttag;
  t_connection const * conn;
  t_account * acc;
  char const * name;
  int first;


  for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */
  for (; text[i]==' '; i++);

  if (text[i]=='\0')
    {
      clienttag = conn_get_clienttag(c);
      message_send_text(c,message_type_info,c,"Semua channel yang dapat diakses:");
    }
  else if (std::strcmp(&text[i],"all")==0)
    {
      clienttag = 0;
      message_send_text(c,message_type_info,c,"Semua channel:");
    }
  else
    {
      clienttag=tag_case_str_to_uint(&text[i]);
      snprintf(msgtemp, sizeof(msgtemp), "Current channels of type %.64s",&text[i]);
      message_send_text(c,message_type_info,c,msgtemp);
    }

  snprintf(msgtemp, sizeof(msgtemp), " -----------name----------- users ----admin/operator----");
  message_send_text(c,message_type_info,c,msgtemp);
  LIST_TRAVERSE_CONST(channellist(),curr)
    {
      channel = (t_channel*)elem_get_data(curr);
      if ((!(channel_get_flags(channel) & channel_flags_clan)) && (!clienttag || !prefs_get_hide_temp_channels() || channel_get_permanent(channel)) &&
      (!clienttag || !channel_get_clienttag(channel) ||
       channel_get_clienttag(channel)==clienttag) &&
       ((channel_get_max(channel)!=0) || //only show restricted channels to OPs and Admins
        ((channel_get_max(channel)==0 && account_is_operator_or_admin(conn_get_account(c),NULL)))) &&
        (!(channel_get_flags(channel) & channel_flags_thevoid)) // don't list TheVoid
    )
    {

      snprintf(msgtemp, sizeof(msgtemp), " %-26.26s %5u - ",
          channel_get_name(channel),
          channel_get_length(channel));

      first = 1;

      for (conn = channel_get_first(channel);conn;conn=channel_get_next())
      {
        acc = conn_get_account(conn);
        if (account_is_operator_or_admin(acc,channel_get_name(channel)) ||
            channel_conn_is_tmpOP(channel,account_get_conn(acc)))
        {
          name = conn_get_loggeduser(conn);
          if (std::strlen(msgtemp) + std::strlen(name) +6 >= MAX_MESSAGE_LEN) break;
          if (!first) std::strcat(msgtemp," ,");
          std::strcat(msgtemp,name);
          if (account_get_auth_admin(acc,NULL)==1) std::strcat(msgtemp,"(A)");
          else if (account_get_auth_operator(acc,NULL)==1) std::strcat(msgtemp,"(O)");
          else if (account_get_auth_admin(acc,channel_get_name(channel))==1) std::strcat(msgtemp,"(a)");
          else if (account_get_auth_operator(acc,channel_get_name(channel))==1) std::strcat(msgtemp,"(o)");
          first = 0;
        }
      }

      message_send_text(c,message_type_info,c,msgtemp);
    }
    }

  return 0;
}

please let me know how to make it in 1 ?

Thank you very much~

2

Re: how to merge commands ?

_handle_ping_command(c, "/ping");
_handle_time_command(c, "/time");
_handle_channels_command(c, "/channels");

? smile

3

Re: how to merge commands ?

xpeh wrote:
_handle_ping_command(c, "/ping");
_handle_time_command(c, "/time");
_handle_channels_command(c, "/channels");

? smile

i mean how to make command /ptc ?
/ptc means /p /time /channel

so if someone type /ptc
it will show his ping, time and channel

4

Re: how to merge commands ?

It was more or less the content of _handle_ptc_command().

5

Re: how to merge commands ?

xpeh wrote:

It was more or less the content of _handle_ptc_command().

can you show the result ?
i have tried but it's always fail

6

Re: how to merge commands ?

I have not tried to compile pvpgn, so i can't test it for you.

7

Re: how to merge commands ?

up ^

8

Re: how to merge commands ?

Jimmy_Aquarius, what's your trouble?


...
static int _handle_ptc_command(t_connection * c, char const * text);
...
static const t_command_table_row extended_command_table[] =
{
    { "/ptc"                , _handle_ptc_command },
...
static int _handle_ptc_command(t_connection * c, char const * text)
{
   _handle_ping_command(c, text);
   _handle_time_command(c, text);
   _handle_channels_command(c, text);

   return 0;
}
Do not ask for support in PM.

9 (edited by Jimmy_Aquarius 22.12.2012 04:24)

Re: how to merge commands ?

HarpyWar wrote:

Jimmy_Aquarius, what's your trouble?


...
static int _handle_ptc_command(t_connection * c, char const * text);
...
static const t_command_table_row extended_command_table[] =
{
    { "/ptc"                , _handle_ptc_command },
...
static int _handle_ptc_command(t_connection * c, char const * text)
{
   _handle_ping_command(c, text);
   _handle_time_command(c, text);
   _handle_channels_command(c, text);

   return 0;
}

my problem was done..
Thanks Harpywar

i don't think so, if the command can be like that

10

Re: how to merge commands ?

Btw, bnalias.conf

Posts: 10

Pages 1

You must login or register to post a reply

Who now at forum

Currently view post: 0 guests, 0 registered users

forums.pvpgn.pro → [EN] The Source Code → how to merge commands ?



Generated in 0.093 seconds (83% PHP - 17% DB) with 20 queries