// When a a client is disconnected void CCharServer::OnClientDisconnect( CClientSocket* thisclient ) { CCharClient* thisclientwc = (CCharClient*)thisclient; if(!thisclientwc->logout) { // Send logout message to friends for(UINT i=0; i<thisclientwc->FriendList.size( ); i++) { CFriendList* Friend = thisclientwc->FriendList.at( i );; CCharClient* otherclient = GetClientByID( Friend->id ); if(otherclient!=NULL) { ChangeMessengerStatus ( thisclientwc, otherclient, 0x08); } } //set logout messga to clan CClans* thisclan = GetClanByID(thisclientwc->clanid); if(thisclan==NULL) return; for(UINT i=0; i<thisclan->ClanMembers.size( ); i++) { CClanMembers* ClanMember = thisclan->ClanMembers.at( i ); CCharClient* otherclient = GetClientByID( ClanMember->id ); if(otherclient!=NULL) ChangeClanStatus (thisclientwc, otherclient, 0xff); } //LMA: Disconnecting a client from chatroom. DisconnectClientFromChat(thisclientwc ); } }
// Messenger actions (add/remove/invite) bool CCharServer::pakMessengerManager ( CCharClient* thisclient, CPacket* P ) { BYTE action = GETBYTE((*P),0); switch (action) { case 0x01://wanna be my friend? { char* nick = new (nothrow) char[P->Size-7]; if(nick==NULL) { Log(MSG_ERROR, "Error allocing memory: pakMessengerManager 1" ); return false; } memcpy( nick, &P->Buffer[1], P->Size-7 ); Log(MSG_INFO,"%s Trying to invite %s",nick,thisclient->charname); CCharClient* otherclient = (CCharClient*) GetClientByName (nick); if(otherclient!=NULL) {//Send friend invitation (check this one) BEGINPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x01 ); ADDWORD ( pak, 0x0000 ); ADDSTRING ( pak, thisclient->charname ); ADDBYTE ( pak, 0x00 ); otherclient->SendPacket(&pak); Log(MSG_INFO,"%s exists, invite sent to %s",nick,otherclient->charname); } else {//This charname doesnt exist BEGINPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x04 ); ADDSTRING ( pak, nick ); ADDBYTE ( pak, 0x00 ); thisclient->SendPacket(&pak); Log(MSG_INFO,"invite: %s doesn't exist",nick); } delete []nick; } break; case 0x02://yes i want { char* nick = new (nothrow) char[P->Size-9]; if(nick==NULL) { Log(MSG_ERROR, "Error allocing memory: pakMessengerManager 2" ); return false; } memcpy( nick, &P->Buffer[3], P->Size-9 ); CCharClient* otherclient = (CCharClient*) GetClientByName (nick); if(otherclient!=NULL) { BEGINPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x02 ); ADDWORD ( pak, thisclient->charid ); ADDBYTE ( pak, 0x00 ); ADDWORD ( pak, 0x0000 ); ADDSTRING ( pak, thisclient->charname ); ADDBYTE ( pak, 0x00); otherclient->SendPacket(&pak); //Add friend to my friend list(sql) if(!DB->QExecute("INSERT INTO list_friend (id,idfriend,namefriend) VALUES (%i,%i,'%s')",otherclient->charid,thisclient->charid,thisclient->charname)) { Log(MSG_WARNING,"error addind %s to %s friend list",otherclient->charname,thisclient->charname); return false; } CFriendList * newfriend1 = new (nothrow) CFriendList; if(newfriend1==NULL) return false; newfriend1->id = otherclient->charid; //friendid strcpy(newfriend1->name, otherclient->charname); //friend name thisclient->FriendList.push_back( newfriend1 ); RESETPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x02 ); ADDWORD ( pak, otherclient->charid ); ADDBYTE ( pak, 0x00 ); ADDWORD ( pak, 0x0000 ); ADDSTRING ( pak, otherclient->charname ); ADDBYTE ( pak, 0x00); thisclient->SendPacket(&pak); //Add me to his friend list (sql) if(!DB->QExecute("INSERT INTO list_friend (id,idfriend,namefriend) VALUES (%i,%i,'%s')", thisclient->charid,otherclient->charid,otherclient->charname)) return false; CFriendList * newfriend2 = new (nothrow) CFriendList; if(newfriend2==NULL) return false; newfriend2->id = thisclient->charid; //friendid strcpy(newfriend2->name, thisclient->charname); //friend name otherclient->FriendList.push_back( newfriend2 ); Log(MSG_INFO,"accept %s ok",nick); } else//not founded { BEGINPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x04 ); ADDSTRING ( pak, nick ); ADDBYTE ( pak, 0x00 ); thisclient->SendPacket(&pak); Log(MSG_INFO,"accept: %s doesn't exist",nick); } delete []nick; } break; case 0x03://no, i dont want { char* nick = new (nothrow) char[P->Size-9]; if(nick==NULL) { Log(MSG_ERROR, "Error allocing memory: pakMessengerManager 3" ); return false; } memcpy( nick, &P->Buffer[3], P->Size-9 ); CCharClient* otherclient = (CCharClient*) GetClientByName (nick); if(otherclient!=NULL) { BEGINPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x03 ); ADDSTRING ( pak, thisclient->charname ); ADDBYTE ( pak, 0x00); otherclient->SendPacket(&pak); Log(MSG_INFO,"refuse: %s ok",nick); } else { BEGINPACKET( pak, 0x7e1 ); ADDBYTE ( pak, 0x04 ); ADDWORD ( pak, 0x0000 ); ADDSTRING ( pak, nick ); ADDBYTE ( pak, 0x00 ); thisclient->SendPacket(&pak); Log(MSG_INFO,"refuse: %s doesn't exist",nick); } } break; case 0x05://delete user. { WORD id = GETWORD ((*P),1); if(!DB->QExecute("DELETE FROM list_friend WHERE id=%i and idfriend=%i",thisclient->charid,id)) { Log(MSG_INFO,"user failed to delete friend slot %i",thisclient->charname,id); return false; } Log(MSG_INFO,"user %s deletes friend slot %i",thisclient->charname,id); CCharClient* otherclient = (CCharClient*) GetClientByID(id); if(otherclient!=NULL) { ChangeMessengerStatus ( thisclient, otherclient, 0x08); } } break; case 0xfa://messenger logout { WORD id = GETWORD ((*P),1); CCharClient* ctherclient = (CCharClient*) GetClientByID(id); if(ctherclient==NULL) return true; ctherclient->logout = true; for(UINT i=0;i<ctherclient->FriendList.size();i++) { CFriendList* thisfriend = ctherclient->FriendList.at( i ); CCharClient* otherclient = (CCharClient*) GetClientByID( thisfriend->id ); if(otherclient!=NULL) { ChangeMessengerStatus ( ctherclient, otherclient, 0x08); } } //Logout in clan ClanLogout ( ctherclient ); } break; default: Log( MSG_INFO, "Friend action unknown: %i", action ); break; } return true; }
// Send away the world IP bool CCharServer::pakRequestWorld( CCharClient* thisclient, CPacket* P ) { if (!thisclient->isLoggedIn) return false; MYSQL_ROW row; MYSQL_RES *result; memset( &thisclient->charname, '\0', 17 ); memcpy( thisclient->charname, &P->Buffer[3], (P->Size-6-4)>16?16:(P->Size-6-4) ); if(!CheckEscapeMySQL(thisclient->charname,17,true)) { Log(MSG_WARNING,"A charname contains incorrect caracters or incorrect size (see warnings above)"); return false; } Log( MSG_INFO,"User %s(%i) selected char '%s'", thisclient->username, thisclient->userid, thisclient->charname); if(!DB->QExecute("UPDATE accounts SET lastchar='%s' WHERE id=%i", thisclient->charname, thisclient->userid)) return false; result = DB->QStore("SELECT host,port,lanip,lansubmask FROM channels WHERE id=%u and owner=%u and type=2", thisclient->channel, Config.ServerID); if(result==NULL) return false; if(mysql_num_rows( result )!=1 ) { Log( MSG_WARNING, "Invalid Server: %i", thisclient->channel ); DB->QFree( ); return false; } row = mysql_fetch_row( result ); BEGINPACKET( pak, 0x711 ); ADDWORD ( pak, atoi(row[1]) ); // PORT ADDDWORD ( pak, thisclient->userid ); ADDDWORD ( pak, 0x87654321 ); if(strcmp(thisclient->ClientSubNet,row[3])==0)//from lan { ADDSTRING( pak, row[2] ); Log(MSG_INFO, "Sending LanIP" ); } else if(strcmp( thisclient->ClientSubNet ,"127.0.0")==0)//same computer { ADDSTRING( pak, "127.0.0.1" ); Log(MSG_INFO, "Sending Localhost IP" ); } else { ADDSTRING( pak, row[0] ); Log(MSG_INFO, "Sending InetIP"); } ADDBYTE ( pak, 0 ); thisclient->SendPacket( &pak ); DB->QFree( ); //CHAR INFORMATION 0 1 2 3 4 result = DB->QStore("SELECT clanid,clan_rank,id,level,classid,rewardpoints FROM characters WHERE char_name='%s'", thisclient->charname); if(result==NULL) return false; if(mysql_num_rows(result)!=1) { Log( MSG_WARNING, "Number of user with charname '%s' is %i", thisclient->charname,mysql_num_rows(result)); DB->QFree( ); return false; } row = mysql_fetch_row( result ); thisclient->clanid = atoi( row[0] ); thisclient->clan_rank = atoi( row[1] ); thisclient->charid = atoi( row[2] ); thisclient->level = atoi( row[3] ); thisclient->job = atoi( row[4] ); thisclient->reward_points=atoi( row[5] ); //LMA: reward points: DB->QFree( ); //MESSENGER INFORMATION // // 0 1 result = DB->QStore("SELECT idfriend,namefriend FROM list_friend WHERE id=%i", thisclient->charid); if(result==NULL) return false; BYTE nfriends = mysql_num_rows(result) & 0xff; RESETPACKET( pak, 0x7e1 );// Friend list command ADDBYTE ( pak, 0x06 );// Sending Friend List ADDBYTE ( pak, nfriends );// # friends while(row = mysql_fetch_row( result )) { CFriendList * newfriend = new CFriendList; assert(newfriend); newfriend->id = atoi(row[0]); //friendid strcpy(newfriend->name, row[1]); //friend name thisclient->FriendList.push_back( newfriend ); ADDWORD (pak, newfriend->id);// friend id ADDWORD (pak, 0x0000 ); CCharClient* otherclient = (CCharClient*) GetClientByID( newfriend->id ); if(otherclient!=NULL) //is online?? { ADDBYTE (pak, 0x07 ); //online ChangeMessengerStatus ( thisclient, otherclient, 0x07); } else { ADDBYTE (pak, 0x08 );//offline } ADDSTRING (pak, newfriend->name); //friend name ADDBYTE (pak, 0x00 ); } thisclient->SendPacket( &pak ); DB->QFree( ); thisclient->logout = false; //SEND CLAN INFORMATION SendClanInfo (thisclient); return true; }