Topic: modification /clan
how to make command like this:
/clan list
/clan online
/clan out
is the source code of /clan list and /clan online same like /friend list ?
please show me the code
this is my source code of /clan
static int _handle_clan_command(t_connection * c, char const * text)
{
t_account * acc;
t_clanmember * member;
t_clan * clan;
if (!(acc = conn_get_account(c))){
ERROR0("got NULL account");
}
text = skip_command(text);
/* FIXME: can get clan as is in creating process */
if((member = account_get_clanmember_forced(acc)) && (clan = clanmember_get_clan(member)) && (clanmember_get_fullmember(member) == 1)) {
if (text[0] == '\0') {
message_send_text(c,message_type_info,c,"usage:");
message_send_text(c,message_type_info,c,"/clan msg <message>");
message_send_text(c,message_type_info,c,"Whispers a message to all your fellow clan members.");
if (clanmember_get_status(member)>=CLAN_SHAMAN) {
message_send_text(c,message_type_info,c,"/clan public /clan pub");
message_send_text(c,message_type_info,c,"Opens the clan channel up to the public so that anyone may enter.");
message_send_text(c,message_type_info,c,"/clan private /clan priv");
message_send_text(c,message_type_info,c,"Closes the clan channel such that only members of the clan may enter.");
message_send_text(c,message_type_info,c,"/clan motd <message>");
message_send_text(c,message_type_info,c,"Update the clan message of the day to <message>.");
message_send_text(c,message_type_info,c,"/clan invite <username>");
message_send_text(c,message_type_info,c,"Invite <username> to your clan.");
}
if (clanmember_get_status(member) == CLAN_CHIEFTAIN) {
message_send_text(c,message_type_info,c,"/clan disband");
message_send_text(c,message_type_info,c,"Disband your clan.");
}
return 0;
}
if (strstart(text,"msg")==0 || strstart(text,"m")==0 || strstart(text,"w")==0 || strstart(text,"whisper")==0) {
char const *msg = skip_command(text);
if (msg[0]=='\0') {
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan msg <message>");
message_send_text(c,message_type_info,c,"Whispers a message to all your fellow clan members.");
}
else {
if (clan_send_message_to_online_members(clan,message_type_whisper,c,msg) >= 1)
message_send_text(c,message_type_info,c,"Pesan telah dikirimkan kepada anggota clan yang sedang online.");
else
message_send_text(c,message_type_info,c,"Semua anggota clanmu sedang tidak online.");
}
}
else
if (clanmember_get_status(member)>=CLAN_SHAMAN) {
if (strstart(text,"public")==0 || strstart(text,"pub")==0) {
if(clan_get_channel_type(clan)!=0) {
clan_set_channel_type(clan,0);
message_send_text(c,message_type_info,c,"Clan channel is opened up!");
}
else
message_send_text(c,message_type_error,c,"Clan channel has already been opened up!");
}
else if (strstart(text,"private")==0 || strstart(text,"priv")==0) {
if(clan_get_channel_type(clan)!=1) {
clan_set_channel_type(clan,1);
message_send_text(c,message_type_info,c,"Clan channel is closed!");
}
else
message_send_text(c,message_type_error,c,"Clan channel has already been closed!");
}
else if (strstart(text,"motd")==0) {
const char * msg=skip_command(text);
if(msg[0]=='\0')
{
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan motd <message>");
message_send_text(c,message_type_info,c,"Update the clan message of the day to <message>.");
}
else
{
clan_set_motd(clan, msg);
message_send_text(c,message_type_info,c,"Clan message of day is updated!");
}
}
else if (strstart(text,"invite")==0 || strstart(text,"inv")==0) {
const char * username = skip_command(text);
t_account * dest_account;
t_connection * dest_conn;
if(username[0]=='\0') {
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan invite <username>");
message_send_text(c,message_type_info,c,"Invite <username> to your clan.");
}
else {
if ((dest_account = accountlist_find_account(username)) && (dest_conn = account_get_conn(dest_account))
&& (account_get_clan(dest_account) == NULL) && (account_get_creating_clan(dest_account) == NULL)) {
if (prefs_get_clan_newer_time() > 0)
clan_add_member(clan, dest_account, CLAN_NEW);
else
clan_add_member(clan, dest_account, CLAN_PEON);
snprintf(msgtemp, sizeof(msgtemp), "Akun %s telah mengundangmu untuk masuk ke clan!", username);
message_send_text(c,message_type_error,c,msgtemp);
snprintf(msgtemp, sizeof(msgtemp), "Kamu telah diundang untuk masuk ke clan %s oleh %s!",clan_get_name(clan),conn_get_chatname(c));
message_send_text(dest_conn,message_type_error,c,msgtemp);
}
else {
snprintf(msgtemp, sizeof(msgtemp), "Akun %s tidak sedang online atau sudah menjadi anggota clanmu!", username);
message_send_text(c,message_type_error,c,msgtemp);
}
}
}
else if (strstart(text,"disband")==0) {
const char * ack = skip_command(text);
if (ack[0]=='\0') {
message_send_text(c,message_type_info,c,"Command ini digunakan untuk membubarkan clanmu!");
message_send_text(c,message_type_info,c,"Jika ingin membubarkan clan, ketik /clan disband yes");
}
else if (strstart(ack,"yes")==0) {
/* PELISH: fixme - Find out better solution! */
if (clanlist_remove_clan(clan) == 0) {
if (clan_get_created(clan) == 1)
clan_remove(clan_get_clantag(clan));
clan_destroy(clan);
message_send_text(c,message_type_info,c,"Clanmu berhasil dibubarkan.");
}
}
}
}
}
else
if ((member = account_get_clanmember_forced(acc)) && (clan = clanmember_get_clan(member)) && (clanmember_get_fullmember(member) == 0)) {
/* User is not in clan, but he can accept invitation to someone */
if (text[0]=='\0') {
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan invite get (show clanname wich you have been invited)");
message_send_text(c,message_type_info,c,"/clan invite accept (accept invitation to clan)");
message_send_text(c,message_type_info,c,"/clan invite decline (decline invitation to clan)");
}
if (strstart(text,"invite")==0 || strstart(text,"inv")==0) {
text = skip_command(text);
if (text[0]=='\0') {
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan invite get (show clanname wich you have been invited)");
message_send_text(c,message_type_info,c,"/clan invite accept (accept invitation to clan)");
message_send_text(c,message_type_info,c,"/clan invite decline (decline invitation to clan)");
}
else if (strstart(text,"get")==0) {
snprintf(msgtemp, sizeof(msgtemp), "Kamu telah diundang ke %s", clan_get_name(clan));
message_send_text(c,message_type_info,c,msgtemp);
}
else if (strstart(text,"accept")==0 || strstart(text,"acc")==0) {
int created = clan_get_created(clan);
clanmember_set_fullmember(member,1);
clanmember_set_join_time(member,std::time(NULL));
snprintf(msgtemp, sizeof(msgtemp), "Sekarang kamu adalah anggota clan dari %s", clan_get_name(clan));
message_send_text(c,message_type_info,c,msgtemp);
if (created > 0) {
DEBUG1("clan %s sudah dibuat", clan_get_name(clan));
return 0;
}
created++;
if (created >= 0) {
clan_set_created(clan, 1);
clan_set_creation_time(clan, std::time(NULL));
/* FIXME: send message "CLAN was be created" to members */
snprintf(msgtemp, sizeof(msgtemp), "Clan %s berhasil dibuat", clan_get_name(clan));
clan_send_message_to_online_members(clan,message_type_whisper,c,msgtemp); /* Send message to all members */
message_send_text(c,message_type_whisper,c,msgtemp); /* also to self */
clan_save(clan);
}
else
clan_set_created(clan, created);
}
else if (strstart(text,"decline")==0 || strstart(text,"dec")==0) {
clan_remove_member(clan,member);
snprintf(msgtemp, sizeof(msgtemp), "Kamu telah menolak undangan menjadi anggota clan %s", clan_get_name(clan));
message_send_text(c,message_type_info,c,msgtemp);
}
}
}
else {
if (text[0]=='\0') {
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan create <clantag> <clanname> (Create a new clan)");
}
else if (strstart(text,"create")==0 || strstart(text,"cre")==0) {
unsigned int i,j;
char clantag[CLANSHORT_NAME_MAX+1];
char clanname[CLAN_NAME_MAX];
for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */
for (; text[i]==' '; i++);
for (j=0; text[i]!=' ' && text[i]!='\0'; i++) /* get clantag */
if (j<sizeof(clantag)-1) clantag[j++] = text[i];
clantag[j] = '\0';
for (; text[i]==' '; i++); /* skip spaces */
for (j=0; text[i]!='\0'; i++) /* get clanname (spaces are allowed) */
if (j<sizeof(clanname)-1) clanname[j++] = text[i];
clanname[j] = '\0';
if ((clantag[0]=='\0') || (clanname[0]=='\0')) {
message_send_text(c,message_type_info,c,"Gunakan:");
message_send_text(c,message_type_info,c,"/clan create <clantag> <clanname> (Create a new clan)");
return 0;
}
if (clan = clanlist_find_clan_by_clantag(str_to_clantag(clantag))) {
message_send_text(c,message_type_error,c,"Clan with your specifed <clantag> allready exist!");
message_send_text(c,message_type_error,c,"Please choice another one.");
return 0;
}
if ((clan = clan_create(conn_get_account(c), str_to_clantag(clantag), clanname, NULL)) && clanlist_add_clan(clan)) {
member = account_get_clanmember_forced(acc);
if (prefs_get_clan_min_invites() == 0) {
clan_set_created(clan, 1);
clan_set_creation_time(clan, std::time(NULL));
snprintf(msgtemp, sizeof(msgtemp), "Clan %s berhasil dibuat!", clan_get_name(clan));
message_send_text(c,message_type_info,c,msgtemp);
clan_save(clan);
}
else {
clan_set_created(clan, -prefs_get_clan_min_invites()+1); //Pelish: +1 means that creator of clan is allready invited
snprintf(msgtemp, sizeof(msgtemp), "Clan %s is pre-created, please invite", clan_get_name(clan));
message_send_text(c,message_type_info,c,msgtemp);
snprintf(msgtemp, sizeof(msgtemp), "at last %u players to your clan by using",prefs_get_clan_min_invites());
message_send_text(c,message_type_info,c,msgtemp);
message_send_text(c,message_type_info,c,"/clan invite <username> command.");
}
}
}
}
return 0;
}