Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

serverdata.cpp

00001 /***************************************************************************
00002  * The contents of this file are subject to the Mozilla Public             *
00003  * License Version 1.1 (the "License"); you may not use this file          *
00004  * except in compliance with the License. You may obtain a copy of         *
00005  * the License at http://www.mozilla.org/MPL/                              *
00006  *                                                                         *
00007  * Software distributed under the License is distributed on an "AS         *
00008  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or              *
00009  * implied. See the License for the specific language governing            *
00010  * rights and limitations under the License.                               *
00011  *                                                                         *
00012  * The Original Code is Game Network Framework (GaNeF).                    *
00013  *                                                                         *
00014  * The Initial Developers of the Original Code are                         *
00015  * Lars Langer and Emanuel Greisen                                         *
00016  * Copyright (C) 2005. Lars Langer & Emanuel Greisen                       *
00017  * All Rights Reserved.                                                    *
00018  *                                                                         *
00019  * Contributor(s):                                                         *
00020  *   none yet....                                                          *
00021  *                                                                         *
00022  ***************************************************************************/
00023 /// @example testserver/testserversnakebite.cpp
00024 #include "serverdata.h"
00025 
00026 #include "serverframework.h"
00027 
00028 unsigned int ServerData::next_data_id = 1000;
00029 mutex ServerData::next_data_id_mutex;
00030 
00031 
00032 ServerData::ServerData( ServerFramework * f, char packet_priority, bool packet_reliable )
00033    : FrameworkData(ServerData::nextDataId()),
00034       server_frame_work(f),
00035       _packet_priority(packet_priority),
00036       _packet_reliable(packet_reliable)
00037 {
00038    server_frame_work->registerData(this);
00039 }
00040 
00041 
00042 ServerData::~ServerData()
00043 {
00044    server_frame_work->unregisterData(this);
00045 }
00046 
00047 unsigned int ServerData::nextDataId( )
00048 {
00049    unsigned int n;
00050    next_data_id_mutex.enter();
00051    n = next_data_id++;
00052    next_data_id_mutex.leave();
00053    return n;
00054 }
00055 
00056 void ServerData::sendUpdateToAll(unsigned char type, bool reliable) const
00057 {
00058    sendUpdate(server_frame_work->getAllClients(), type, reliable);
00059 }
00060 
00061 void ServerData::sendUpdate( const std::map< unsigned int, Client * > & clientlist, unsigned char type, bool reliable) const
00062 {
00063    // No need to do all this if we send to nobody
00064    if(clientlist.empty())
00065       return;
00066    // Construct an update packet
00067    ServerPacket * packet = new ServerPacket(this, type, _packet_priority, reliable);
00068    fillUpdatePacket(packet, type);
00069    server_frame_work->enqueuePacket(packet, clientlist);
00070 }
00071 
00072 void ServerData::sendUpdate( Client * client, unsigned char type, bool reliable) const
00073 {
00074    std::map< unsigned int, Client * > map;
00075    map.clear();
00076    map.insert(std::make_pair(client->getId(), client));
00077    sendUpdate(map,type,reliable);
00078 }
00079 
00080 void ServerData::sendCreateObjectToAll() const
00081 {
00082    sendCreateObject(server_frame_work->getAllClients());
00083 }
00084 
00085 void ServerData::sendCreateObject( const std::map< unsigned int, Client * > & clientlist ) const
00086 {
00087    // No need to do all this if we send to nobody
00088    if(clientlist.empty())
00089       return;
00090    // Construct an create object-packet
00091    ServerPacket * packet = ServerPacket::initCreateObjectPacket(this, _packet_priority);
00092    fillCreateObjectPacket(packet);
00093    server_frame_work->enqueuePacket(packet, clientlist);
00094 }
00095 
00096 void ServerData::sendCreateObject( Client * client ) const
00097 {
00098    std::map< unsigned int, Client * > map;
00099    map.clear();
00100    map.insert(std::make_pair(client->getId(), client));
00101    sendCreateObject(map);
00102 }
00103 
00104 void ServerData::sendDestroyToAll() const
00105 {
00106    sendDestroy(server_frame_work->getAllClients());
00107 }
00108 
00109 void ServerData::sendDestroy( const std::map< unsigned int, Client * > & clientlist ) const
00110 {
00111    // No need to do all this if we send to nobody
00112    if(clientlist.empty())
00113       return;
00114    // Construct a delete/destroy object-packet
00115    ServerPacket * packet = ServerPacket::initDestroyObjectPacket(this, _packet_priority);
00116    server_frame_work->enqueuePacket(packet, clientlist);
00117 }
00118 
00119 void ServerData::sendDestroy( Client * client ) const
00120 {
00121    std::map< unsigned int, Client * > map;
00122    map.clear();
00123    map.insert(std::make_pair(client->getId(), client));
00124    sendDestroy(map);
00125 }
00126 
00127 
00128 

Generated on Mon Feb 6 12:24:50 2006 for Ganef by  doxygen 1.4.4