Changeset edfd1d0 in network-game
- Timestamp:
- Dec 25, 2012, 6:27:14 PM (12 years ago)
- Branches:
- master
- Children:
- 4c202e0
- Parents:
- baaf6c8
- Files:
-
- 1 added
- 6 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
client/makefile
rbaaf6c8 redfd1d0 3 3 FLAGS = $(LIB_FLAGS) 4 4 COMMON_PATH = ../common 5 DEPENDENCIES = Message.o chat.o GuiComponent.o Window.o Textbox.o Button.o5 DEPENDENCIES = Message.o Player.o chat.o GuiComponent.o Window.o Textbox.o Button.o 6 6 7 7 gameClient : Client/main.cpp $(DEPENDENCIES) … … 9 9 10 10 Message.o : $(COMMON_PATH)/Message.cpp 11 $(CC) -c -o $@ $? $(FLAGS) 12 13 Player.o : $(COMMON_PATH)/Player.cpp 11 14 $(CC) -c -o $@ $? $(FLAGS) 12 15 -
common/Common.h
rbaaf6c8 redfd1d0 2 2 #define _COMMON_H 3 3 4 void set_nonblock(int sock) 4 #include <fcntl.h> 5 #include <assert.h> 6 7 void set_nonblock(int sock); 8 9 typedef struct 5 10 { 6 #ifdef WIN32 7 unsigned long mode = 1; 8 ioctlsocket(sock, FIONBIO, &mode); 9 #else 10 int flags; 11 flags = fcntl(sock, F_GETFL,0); 12 assert(flags != -1); 13 fcntl(sock, F_SETFL, flags | O_NONBLOCK); 14 #endif 15 } 11 int x; 12 int y; 13 } PLAYER_POS; 16 14 17 15 #endif -
common/Message.h
rbaaf6c8 redfd1d0 6 6 #define MSG_TYPE_LOGOUT 3 7 7 #define MSG_TYPE_CHAT 4 8 #define MSG_TYPE_PLAYER 5 8 9 9 10 typedef struct -
common/Player.cpp
rbaaf6c8 redfd1d0 10 10 this->name = name; 11 11 this->password = password; 12 this->pos.x = 200; 13 this->pos.y = 200; 12 14 13 15 cout << "Created new player: " << this->name << endl; … … 18 20 this->name = name; 19 21 this->password = ""; 22 this->pos.x = 200; 23 this->pos.y = 200; 20 24 this->addr = addr; 21 25 … … 31 35 this->addr = addr; 32 36 } 37 38 void Player::clearSensitiveInfo() 39 { 40 this->password = ""; 41 this->addr.sin_family = 0; 42 this->addr.sin_port = 0; 43 this->addr.sin_addr.s_addr = 0; 44 } -
common/Player.h
rbaaf6c8 redfd1d0 4 4 #include <netinet/in.h> 5 5 #include <string> 6 7 #include "Common.h" 6 8 7 9 using namespace std; … … 14 16 15 17 void setAddr(sockaddr_in addr); 18 void clearSensitiveInfo(); 16 19 17 20 string name; 18 21 string password; 19 22 sockaddr_in addr; 23 PLAYER_POS pos; 20 24 }; 21 25 -
server/DataAccess.h
rbaaf6c8 redfd1d0 6 6 #include <mysql/mysql.h> 7 7 8 #include " Player.h"8 #include "../common/Player.h" 9 9 10 10 using namespace std; -
server/makefile
rbaaf6c8 redfd1d0 3 3 FLAGS = $(LIB_FLAGS) 4 4 COMMON_PATH = ../common 5 DEPENDENCIES = Message.o Player.o DataAccess.o5 DEPENDENCIES = Common.o Message.o Player.o DataAccess.o 6 6 7 7 server : server.cpp $(DEPENDENCIES) 8 8 $(CC) -o $@ $+ $(FLAGS) 9 9 10 Common.o : $(COMMON_PATH)/Common.cpp 11 $(CC) -c -o $@ $? 12 10 13 Message.o : $(COMMON_PATH)/Message.cpp 14 $(CC) -c -o $@ $? 15 16 Player.o : $(COMMON_PATH)/Player.cpp 11 17 $(CC) -c -o $@ $? 12 18 -
server/server.cpp
rbaaf6c8 redfd1d0 7 7 #include <vector> 8 8 #include <algorithm> 9 10 #include <fcntl.h> 11 #include <assert.h> 9 #include <cstring> 12 10 13 11 #include <sys/socket.h> … … 16 14 #include <arpa/inet.h> 17 15 16 /* 18 17 #include <openssl/bio.h> 19 18 #include <openssl/ssl.h> 20 19 #include <openssl/err.h> 20 */ 21 21 22 22 #include "../common/Compiler.h" 23 #include "../common/Common.h" 23 24 #include "../common/Message.h" 24 #include "../common/Common.h" 25 26 #include "Player.h" 25 #include "../common/Player.h" 26 27 27 #include "DataAccess.h" 28 28 … … 63 63 64 64 return NULL; 65 } 66 67 void broadcastPlayerPositions(vector<Player> &vec, int sock) 68 { 69 vector<Player>::iterator it, it2; 70 NETWORK_MSG serverMsg; 71 72 serverMsg.type = MSG_TYPE_PLAYER; 73 74 for (it = vec.begin(); it != vec.end(); it++) 75 { 76 strncpy(serverMsg.buffer, (char*)&*it, sizeof(Player)); 77 78 for (it2 = vec.begin(); it2 != vec.end(); it2++) 79 { 80 if ( sendMessage(&serverMsg, sock, &(it2->addr)) < 0 ) 81 error("sendMessage"); 82 } 83 } 65 84 } 66 85 … … 73 92 vector<Player> vctPlayers; 74 93 75 SSL_load_error_strings();76 ERR_load_BIO_strings();77 OpenSSL_add_all_algorithms();94 //SSL_load_error_strings(); 95 //ERR_load_BIO_strings(); 96 //OpenSSL_add_all_algorithms(); 78 97 79 98 if (argc < 2) { … … 127 146 error("sendMessage"); 128 147 } 129 } 130 148 149 broadcastPlayerPositions(vctPlayers, sock); 150 } 131 151 } 132 152
Note:
See TracChangeset
for help on using the changeset viewer.