Shadowrun: Awakened 29 September 2011 - Build 871
LeaveChannelMessage.cpp
Go to the documentation of this file.
00001 #include "LeaveChannelMessage.h"
00002 #include "LeaveChannelPacket.h"
00003 #include "ClientRegister.h"
00004 #include "WorldServer.h"
00005 #include "ReplyPacket.h"
00006 
00007 namespace SraNetwork
00008 {
00009     LeaveChannelMessage::LeaveChannelMessage(void)
00010     {
00011     }
00012 
00013 
00014     LeaveChannelMessage::~LeaveChannelMessage(void)
00015     {
00016     }
00017 
00018 
00019     SraPacket* LeaveChannelMessage::createPacketFromData(const unsigned char* data)
00020     {
00021         return (LeaveChannelPacket*)data;
00022     }
00023 
00024     void LeaveChannelMessage::process(MessageData* message)
00025     {
00026         //Client has sent login data
00027         std::cout << "Processing leave channel message" << std::endl;
00028         
00029         ClientRegister* reg = ClientRegister::getInstance();
00030         const SraClientData* client = reg->getClientFromAddress( message->address );
00031         if (client == NULL)
00032         {
00033             printf("Error: A non existing client is used in LeaveChannelMeesage::process\n");
00034             return;
00035         }
00036 
00037         LeaveChannelPacket packet;
00038         packet.Deserialize( &message->stream );
00039         
00040         // Send a join message to the chat server
00041         RakPeerInterface* chatInterface = WorldServer::getChatinterface(packet.channelId);
00042         if (chatInterface == NULL)
00043         {
00044             //If the channel join failed, send a reply to the client
00045             RakNet::RakPeerInterface *clientI = SraNetwork::WorldServer::getClientInterface();
00046 
00047             BitStream stream;
00048 
00049             ReplyPacket rp;
00050             rp.replyCode = ReplyPacket::FAIL;
00051             rp.messageOpCode = ID_CHAT_CHANNEL_REGISTER;
00052             rp.replyMessage = "LeaveChannel failed, please check the channel name.";
00053             rp.Serialize(&stream);
00054             clientI->Send( &stream, 
00055                 MEDIUM_PRIORITY, RELIABLE_ORDERED, 0, message->address, false);
00056         }
00057         else
00058         {
00059             printf("Forwarding request to the chat server\n");
00060             // We will simply forward the request to the chat server now.
00061             // The chat server will check if the requested channel exists and
00062             // if the player is allowed to join it.
00063             // We don't need to send a client answer either, because the chat
00064             // server will send it's own IP
00065             chatInterface->Send(&message->stream, MEDIUM_PRIORITY, RELIABLE_ORDERED, 0, message->address, false);
00066         }
00067     }
00068 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net