Shadowrun: Awakened 29 September 2011 - Build 871
ClientRegister.h
Go to the documentation of this file.
00001 /*
00002 * Client register - Stores active clients
00003 *
00004 * @Author Michael <Tharbas> Matzen
00005 *
00006 * This program is free software; you can redistribute it and/or modify it
00007 * under the terms of the GNU General Public License as published by the Free
00008 * Software Foundation; either version 2 of the License, or (at your option)
00009 * any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful, but WITHOUT
00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00014 * more details.
00015 *
00016 * You should have received a copy of the GNU General Public License along with
00017 * this program; if not, write to the Free Software Foundation, Inc., 51
00018 * Franklin St, Fifth Floor, Boston, MA 02110, USA
00019 * 
00020 */
00021 #pragma once
00022 
00023 #include "WindowsIncludes.h"
00024 #include <tbb_thread.h>
00025 #include <task_scheduler_init.h>
00026 #include <concurrent_hash_map.h>
00027 #include <concurrent_vector.h>
00028 #include <task.h>
00029 #include <stdio.h>
00030 #include <string>
00031 
00032 #include "Utils.h"
00033 #include "SraNetworkShared.h"
00034 #include "BasicCharacterInfo.h"
00035 
00036 // SQL includes:
00037 #include "DbConnectionFactory.h"
00038 #include "DbProcedures.h"
00039 #include "DbStream.h"
00040 
00041 using namespace RakNet;
00042 using namespace std;
00043 
00044 namespace SraNetwork{
00045 
00046     // The client register class, used as an interface between the database
00047     // and the world server. Encapsulates all character related functions.
00048     // TODO: Auto-generate method stubs.
00049     class ClientRegister
00050     {
00051         //Hash-Map compare function for system addresses.
00052         struct SystemAddressCompare {
00053             //Simple 'hash', we're simply using the binaryaddress, maybe we need somthing better.
00054             static size_t hash( const SystemAddress& a)
00055             {
00056                 return SystemAddress::ToInteger(a);
00057             }
00058             //Since the SystemAddress class has a compare function, use this to compare addresses
00059             static bool equal( const SystemAddress& a, const SystemAddress& b)
00060             {
00061                 return a.EqualsExcludingPort(b);
00062             }
00063         };
00064 
00065     private:
00066         ClientRegister(void);
00067         ~ClientRegister(void);
00068         //tbb::concurrent_vector<SraNetwork::SraClientData> clients;
00075         tbb::concurrent_hash_map<SystemAddress, SraClientData, SystemAddressCompare>  clientAddressRegister;
00076         // Singleton-instance yea yea singletons are bad and evil but easy to use ;)
00077         static ClientRegister* instance;
00078 
00079 
00080         //NOTE: Naively removed to ensure it builds in test
00081         //SraData::DbProcedureManager dbManager;
00082     public:
00086         static ClientRegister* getInstance();
00087 
00092         void addClient( SystemAddress address, SraClientData client);
00093 
00095         const SraClientData* getClientFromAddress( SystemAddress address);
00096 
00098         const SystemAddress* getAddressFromClient( const SraClientData* data);
00099 
00101         const SystemAddress* getAddressFromClientID( const int clientID);
00102 
00104         void removeClient(const SystemAddress address);
00105 
00107         void removeClient( const SraClientData* data);
00108 
00113         int loginClient( const string& username, const string& password, SystemAddress address);
00114 
00118         int createCharacterForPlayer(int raceId, SystemAddress address, int clientID );
00119 
00121         void getPlayersForClient( const int clientID, const int* outPlayerIDs);
00122 
00128         bool checkForValidCharacterInfo( const BasicCharacterInfo* info, RakString* resultMessage);
00129 
00130     private:
00131         int nextID;
00132     };
00133 }

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