![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 * Chat Server - This chat server will handle all chat related stuff, 00003 * i.e. a mapping of playerIDs - chatGroups etc 00004 * 00005 * @Author Michael Matzen <mim@informatik.uni-kiel.de> 00006 * 00007 * This program is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU General Public License as published by the Free 00009 * Software Foundation; either version 2 of the License, or (at your option) 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00015 * more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along with 00018 * this program; if not, write to the Free Software Foundation, Inc., 51 00019 * Franklin St, Fifth Floor, Boston, MA 02110, USA 00020 * 00021 */ 00022 #pragma once 00023 00024 #include <stdio.h> 00025 #include <hash_map> 00026 #include <vector> 00027 #include <concurrent_hash_map.h> 00028 #include "RakPeerInterface.h" 00029 00030 #include "SraNetworkShared.h" 00031 #include "SraPacket.h" 00032 00033 using namespace RakNet; 00034 namespace SraNetwork { 00035 00036 //Hash-Map compare function for system addresses. 00037 struct SystemAddressCompare { 00038 //Simple 'hash', we're simply using the binaryaddress, maybe we need somthing better. 00039 static size_t hash( const SystemAddress& a) 00040 { 00041 return 1; 00042 } 00043 //Since the SystemAddress class has a compare function, use this to compare addresses 00044 static bool equal( const SystemAddress& a, const SystemAddress& b) 00045 { 00046 return a.EqualsExcludingPort(b); 00047 } 00048 }; 00049 00050 class ChatServer 00051 { 00052 00053 public: 00054 ChatServer(void); 00055 ~ChatServer(void); 00056 00057 static void ServerConnectionThread(); 00058 static void ClientConnectionThread(); 00059 00060 private: 00061 // A mapping of client adresses to a unique int identifier 00062 static tbb::concurrent_hash_map<SystemAddress, unsigned int, SystemAddressCompare> m_vChatUserRegister; 00063 00064 // Every client has a list of pending messages. 00065 // This is a map of [indexInUserRegister->listOfMessages] 00066 static tbb::concurrent_hash_map<unsigned int, std::vector<RakString>> m_mPendingUserMessages; //Buffered messages for a user 00067 00068 // Every client has a list of chat groups that he is assigned to, basically 00069 // the sole use of this list is to keep track of the number of chatgroups 00070 // a user has joined. 00071 // This is a map of [indexInUserRegister->listOfChatGroups] 00072 static tbb::concurrent_hash_map<unsigned int, std::vector<int>> m_mUserChatGroupMap; 00073 00074 // A list of all the existing chat groups with all the user ids 00075 // This is a map of [chatGroupID->indexInUserRegister] 00076 static tbb::concurrent_hash_map<unsigned int, std::vector<int>> m_mChatGroupMap; 00077 00078 // The last client ID that has been used to assign a SystemAddress to a userListIndex 00079 static unsigned int lastUsedClientId; 00080 00081 // The maximum number of chat groups, this is just for avoiding a group creation spam 00082 static const int MAX_NUMBER_OF_CHAT_GROUPS = 2048; 00083 00084 // The maximum number of chats a single user is allowed to join. 00085 static const int MAX_NUMBER_OF_CHAT_GROUPS_PER_USER = 16; 00086 00087 // The maximum number of users per chat group 00088 static const int MAX_NUMBER_OF_USERS_PER_GROUP = 2048; 00089 }; 00090 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.