static void on_receive (int socket_fd) { printf ("enter on receive...\n"); struct message msg; while (1) { ssize_t len = get_message (socket_fd, &msg); if (len < 0) { break; } /* 用户掉线或者主动退出游戏 */ else if (len == 0) { user_offline (socket_fd); break; } else { services[msg.type] (socket_fd, &msg); } } printf ("exit on receive...\n"); }
static int service_GetContactInfo(WPARAM wParam, LPARAM lParam) { CCSDATA * ccs = (CCSDATA*)lParam; if(user_offline()) return 1; return contacts_get_contact_info(ccs->hContact, ccs->wParam); }
/* service_BasicSearch: * implement case insensitive search */ static int service_BasicSearch(WPARAM wParam, LPARAM lParam) { char * nickname; if(user_offline()) return 0; nickname = util_loc2utf((char*)lParam); QueueUserAPC( service_BasicSearch_ResultAPC, g_hMainThread, (ULONG_PTR)(userlist_user_exists(nickname) ? strdup(nickname): 0)); free(nickname); return 1; /* search started (imaginary handle 1) */ }
static int service_SetAwayMsg(WPARAM wParam, LPARAM lParam) { /*int status_mode = wParam;*/ LPCSTR szMessage = (LPCSTR)lParam; /* note that szMessage can be NULL! */ char * message; if(user_offline()) return 1; /* convert to utf and set */ message = util_loc2utf(szMessage ? szMessage: ""); user_set_awaymsg(message); free(message); return 0; /* success */ }
static int service_AddToList(WPARAM wParam, LPARAM lParam) { int added; char * nickname; /* wParam = flags */ PROTOSEARCHRESULT * psresult = (PROTOSEARCHRESULT*)lParam; if(user_offline()) return 0; nickname = util_loc2utf(psresult->nick); added = (int)contacts_add_contact(nickname, 1); free(nickname); return added; }
void on_exit_game (int fd, struct message *msg) { printf ("on_exit_game\n"); user_offline (fd); }