Changeset 777 for code/branches/FICN/src/network/Server.cc
- Timestamp:
- Dec 31, 2007, 7:40:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/Server.cc
r660 r777 11 11 // 12 12 13 #include <iostream> 13 14 15 #include "ConnectionManager.h" 16 #include "PacketTypes.h" 17 #include "GameStateManager.h" 18 #include "ClientInformation.h" 19 //#include "NetworkFrameListener.h" 14 20 #include "Server.h" 15 21 16 namespace network{17 22 23 namespace network 24 { 18 25 /** 19 20 21 22 Server::Server() {26 * Constructor for default values (bindaddress is set to ENET_HOST_ANY 27 * 28 */ 29 Server::Server() { 23 30 packet_gen = PacketGenerator(); 24 31 clients = new ClientInformation(true); … … 28 35 29 36 /** 30 31 32 33 34 Server::Server(int port, std::string bindAddress) {37 * Constructor 38 * @param port Port to listen on 39 * @param bindAddress Address to listen on 40 */ 41 Server::Server(int port, std::string bindAddress) { 35 42 packet_gen = PacketGenerator(); 36 43 clients = new ClientInformation(); … … 40 47 41 48 /** 42 43 44 45 46 Server::Server(int port, const char *bindAddress) {49 * Constructor 50 * @param port Port to listen on 51 * @param bindAddress Address to listen on 52 */ 53 Server::Server(int port, const char *bindAddress) { 47 54 packet_gen = PacketGenerator(); 48 55 clients = new ClientInformation(); … … 52 59 53 60 /** 54 55 56 void Server::open() {61 * This function opens the server by creating the listener thread 62 */ 63 void Server::open() { 57 64 connection->createListener(); 58 65 return; … … 60 67 61 68 /** 62 63 64 void Server::close() {69 * This function closes the server 70 */ 71 void Server::close() { 65 72 connection->quitListener(); 66 73 return; … … 68 75 69 76 /** 70 71 72 73 74 bool Server::sendMSG(std::string msg) {77 * This function sends out a message to all clients 78 * @param msg message 79 * @return true/false 80 */ 81 bool Server::sendMSG(std::string msg) { 75 82 ENetPacket *packet = packet_gen.chatMessage(msg.c_str()); 76 83 //std::cout <<"adding packets" << std::endl; … … 79 86 return connection->sendPackets(); 80 87 } 88 81 89 /** 82 83 84 85 86 bool Server::sendMSG(const char *msg) {90 * This function sends out a message to all clients 91 * @param msg message 92 * @return true/false 93 */ 94 bool Server::sendMSG(const char *msg) { 87 95 ENetPacket *packet = packet_gen.chatMessage(msg); 88 96 std::cout <<"adding Packets" << std::endl; … … 90 98 //std::cout <<"added packets" << std::endl; 91 99 if (connection->sendPackets()){ 92 93 100 std::cout << "Sucessfully" << std::endl; 101 return true; 94 102 } 95 103 return false; … … 97 105 98 106 /** 99 100 101 102 103 void Server::tick(float time) {107 * Run this function once every tick 108 * calls processQueue and updateGamestate 109 * @param time time since last tick 110 */ 111 void Server::tick(float time) { 104 112 processQueue(); 105 113 updateGamestate(); … … 108 116 109 117 /** 110 111 112 void Server::processQueue() {118 * processes all the packets waiting in the queue 119 */ 120 void Server::processQueue() { 113 121 ENetPacket *packet; 114 122 int clientID=-1; … … 121 129 122 130 /** 123 124 125 void Server::updateGamestate() {131 * takes a new snapshot of the gamestate and sends it to the clients 132 */ 133 void Server::updateGamestate() { 126 134 gamestates->update(); 127 135 //std::cout << "updated gamestate, sending it" << std::endl; … … 131 139 132 140 /** 133 134 135 bool Server::sendGameState() {141 * sends the gamestate 142 */ 143 bool Server::sendGameState() { 136 144 std::cout << "starting gamestate" << std::endl; 137 145 ClientInformation *temp = clients; … … 160 168 if(added) 161 169 return connection->sendPackets(); 162 else return false;163 //return true;170 else 171 return false; 164 172 } 165 173 166 void Server::processAck( ack *data, int clientID) {174 void Server::processAck( ack *data, int clientID) { 167 175 clients->findClient(clientID)->setGamestateID(data->a); 168 176 }
Note: See TracChangeset
for help on using the changeset viewer.