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~