From: Manuel A. F. M. <ma...@us...> - 2005-02-18 03:31:49
|
Update of /cvsroot/once/oncecode/src/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1903/src/server Modified Files: occontactlist.cpp occontactlist.h ocmsghandler.cpp Log Message: Activate the handlers so we can add and remove contacts from the client Index: occontactlist.cpp =================================================================== RCS file: /cvsroot/once/oncecode/src/server/occontactlist.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** occontactlist.cpp 16 Feb 2005 15:16:26 -0000 1.2 --- occontactlist.cpp 18 Feb 2005 03:31:34 -0000 1.3 *************** *** 23,26 **** --- 23,28 ---- #include "common/occontactlistmsg.h" + #include "common/occontactaddmsg.h" + #include "common/occontactrmmsg.h" #include "common/occhatmsg.h" #include "common/ocplayer.h" *************** *** 240,244 **** serversys->GetDBMgr()->Escape(cscontactcharname, contact_charname); contact_charname = cscontactcharname.GetData(); ! qry = "SELECT uid,aid FROM usr_characters WHERE charname='" + string(contact_charname) + "'"; iocDBResult* result2 = serversys->GetDBMgr()->ExecuteQuery(qry.c_str()); if (!result2 || (result2->GetNumResults() != 1)) --- 242,247 ---- serversys->GetDBMgr()->Escape(cscontactcharname, contact_charname); contact_charname = cscontactcharname.GetData(); ! qry = "SELECT uid,aid,last_login FROM usr_characters WHERE charname='" + ! string(contact_charname) + "'"; iocDBResult* result2 = serversys->GetDBMgr()->ExecuteQuery(qry.c_str()); if (!result2 || (result2->GetNumResults() != 1)) *************** *** 254,257 **** --- 257,261 ---- string contact_uid = (const char*) row2->GetData(0); string contact_aid = (const char*) row2->GetData(1); + string last_login = (const char*) row2->GetData(2); //delete result2; //delete row2; *************** *** 282,288 **** --- 286,310 ---- "contact player '%s', type '%d', comment '%s')\n", player->GetPlayerName(), contact_charname, type, comment); + SendReply(player->GetNetLink(), "Info: Successfully added contact"); + // send notification about this one + ocContactListMsg* msg = new ocContactListMsg; + msg->charname = contact_charname; + msg->type = type; + msg->comment = comment; + msg->last_login = last_login.c_str(); + msg->connected = world->FindPlayer(msg->charname); + if (msg->connected) + SendReply(player->GetNetLink(), "Your contact '" + + msg->charname + "' is on-line"); + else + SendReply(player->GetNetLink(), "Your contact '" + + msg->charname + "' is off-line"); + SendContactStatus(player, msg); + delete msg; + + return true; } *************** *** 320,321 **** --- 342,387 ---- return true; } + + + //------------------ ocHandleContactAdd -------------------------- + int ocHandleContactAdd::GetMessageType() {return ocContactAddMsg::ocClassID;} + + bool ocHandleContactAdd::HandleMessage(iSerial *ser_msg, ocPlayerBehaviour* player) + { + SYSTRACE("ocHandleContactAdd::HandleMessage"); + ocContactAddMsg* msg = (ocContactAddMsg*)ser_msg; + + serversys->PrintMessage("Info: Contact list add handler: '%s: %s'\n", + player->GetPlayerName(), + msg->charname.GetData()); + + if(msg->charname.IsEmpty()) + return false; + + ocContactList::AddContact(player, msg->charname.GetData(), + msg->type, msg->comment.GetData()); + + return true; + } + + + //------------------ ocHandleContactAdd -------------------------- + int ocHandleContactRemove::GetMessageType() {return ocContactRmMsg::ocClassID;} + + bool ocHandleContactRemove::HandleMessage(iSerial *ser_msg, ocPlayerBehaviour* player) + { + SYSTRACE("ocHandleContactRemove::HandleMessage"); + ocContactRmMsg* msg = (ocContactRmMsg*)ser_msg; + + serversys->PrintMessage("Info: Contact list remove handler: '%s: %s'\n", + player->GetPlayerName(), + msg->charname.GetData()); + + if(msg->charname.IsEmpty()) + return false; + + ocContactList::RemoveContact(player, msg->charname.GetData()); + + return true; + } + Index: ocmsghandler.cpp =================================================================== RCS file: /cvsroot/once/oncecode/src/server/ocmsghandler.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** ocmsghandler.cpp 12 Feb 2005 19:23:16 -0000 1.33 --- ocmsghandler.cpp 18 Feb 2005 03:31:40 -0000 1.34 *************** *** 30,34 **** --- 30,37 ---- #include "common/ocnewusermsg.h" #include "common/ocnewcharmsg.h" + #include "common/ocdelcharmsg.h" #include "common/ocjoinmsg.h" + #include "common/occontactaddmsg.h" + #include "common/occontactrmmsg.h" #include "common/occhatmsg.h" #include "common/ocfactory.h" *************** *** 37,40 **** --- 40,44 ---- #include "server/ochdlchat.h" #include "server/ocuseraccount.h" + #include "server/occontactlist.h" #include "server/ochdlplayeraction.h" #include "server/ocsvrcontmanager.h" *************** *** 140,144 **** --- 144,154 ---- factory->RegClass<ocNewUserMsg>(); factory->RegClass<ocNewCharacterMsg>(); + factory->RegClass<ocDelCharacterMsg>(); factory->RegClass<ocJoinGameMsg>(); + + RegHandler(new ocHandleContactAdd, this); + factory->RegClass<ocContactAddMsg>(); + RegHandler(new ocHandleContactRemove, this); + factory->RegClass<ocContactRmMsg>(); } Index: occontactlist.h =================================================================== RCS file: /cvsroot/once/oncecode/src/server/occontactlist.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** occontactlist.h 16 Feb 2005 15:16:26 -0000 1.2 --- occontactlist.h 18 Feb 2005 03:31:40 -0000 1.3 *************** *** 48,50 **** --- 48,80 ---- }; + /** + * Handles ocContactAdd messages on the server side. + */ + class ocHandleContactAdd : public iPacketHandlerServer { + public: + ocHandleContactAdd() {} + virtual ~ocHandleContactAdd() {} + + //---------- iPacketHandlerServer interface ------------- + virtual int GetMessageType(); + virtual bool HandleMessage(iSerial *ser_msg, + ocPlayerBehaviour* player); + }; + + + /** + * Handles ocContactRemove messages on the server side. + */ + class ocHandleContactRemove : public iPacketHandlerServer { + public: + ocHandleContactRemove() {} + virtual ~ocHandleContactRemove() {} + + //---------- iPacketHandlerServer interface ------------- + virtual int GetMessageType(); + virtual bool HandleMessage(iSerial *ser_msg, + ocPlayerBehaviour* player); + }; + + #endif // SERVER_OCCONTACTLIST_H |