![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 #include "JoinChannelMessage.h" 00002 #include "ClientRegister.h" 00003 #include "WorldServer.h" 00004 #include "ReplyPacket.h" 00005 #include "JoinChannelPacket.h" 00006 00007 namespace SraNetwork 00008 { 00009 JoinChannelMessage::JoinChannelMessage(void) 00010 { 00011 } 00012 00013 00014 JoinChannelMessage::~JoinChannelMessage(void) 00015 { 00016 } 00017 00018 SraPacket* JoinChannelMessage::createPacketFromData(const unsigned char* data) 00019 { 00020 return (JoinChannelPacket*)data; 00021 } 00022 00023 void JoinChannelMessage::process(MessageData* message) 00024 { 00025 //Client has sent login data 00026 std::cout << "Processing join channel message" << std::endl; 00027 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 JoinChannelMessage::process\n"); 00034 return; 00035 } 00036 00037 JoinChannelPacket 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 = "JoinChannel 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 00066 // Add the client address to the forwarded packet. 00067 packet.clientAddress = message->address; 00068 BitStream fwdClientStream; 00069 packet.Serialize(&fwdClientStream); 00070 chatInterface->Send(&fwdClientStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, true); 00071 } 00072 } 00073 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.