source: network-game/common/MessageContainer.cpp@ 64a1f4e

Last change on this file since 64a1f4e was 06fc7f7, checked in by dportnoy <dmp1488@…>, 11 years ago

getMsgTypeString is now defined in MessageContainer.cpp and the message types have been converted to an enum

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include "MessageContainer.h"
2
3#include <iostream>
4
5using namespace std;
6
7MessageContainer::MessageContainer() {
8}
9
10MessageContainer::MessageContainer(const MessageContainer& mc) {
11 this->msg = mc.msg;
12 this->clientAddr = mc.clientAddr;
13 this->isAcked = mc.isAcked;
14 this->timeAcked = mc.timeAcked;
15}
16
17MessageContainer::MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr) {
18 this->clientAddr = clientAddr;
19 this->msg = msg;
20 this->isAcked = false;
21 this->timeAcked = 0;
22}
23
24MessageContainer::~MessageContainer() {
25}
26
27bool MessageContainer::getAcked() {
28 return this->isAcked;
29}
30
31unsigned long long MessageContainer::getTimeAcked() {
32 return this->timeAcked;
33}
34
35NETWORK_MSG* MessageContainer::getMessage() {
36 return &msg;
37}
38
39void MessageContainer::setAcked(bool acked) {
40 cout << "acked before: " << this->isAcked << endl;
41 this->isAcked = acked;
42 cout << "acked after: " << this->isAcked << endl;
43}
44
45
46void MessageContainer::setTimeAcked(unsigned long long time) {
47 this->timeAcked = time;
48}
49
50string MessageContainer::getMsgTypeString(int msgType) {
51 switch(msgType) {
52 case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
53 case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
54 case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
55 case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
56 case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
57 case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
58 case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
59 case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
60 case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
61 case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
62 case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
63 case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
64 case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
65 case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
66 case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
67 case MSG_TYPE_CREATE_GAME: return "MSG_TYPE_CREATE_GAME";
68 case MSG_TYPE_JOIN_GAME: return "MSG_TYPE_JOIN_GAME";
69 case MSG_TYPE_LEAVE_GAME: return "MSG_TYPE_LEAVE_GAME";
70 case MSG_TYPE_GAME_INFO: return "MSG_TYPE_GAME_INFO";
71 case MSG_TYPE_JOIN_GAME_SUCCESS: return "MSG_TYPE_JOIN_GAME_SUCCESS";
72 case MSG_TYPE_JOIN_GAME_FAILURE: return "MSG_TYPE_JOIN_GAME_FAILURE";
73 case MSG_TYPE_JOIN_GAME_ACK: return "MSG_TYPE_JOIN_GAME_ACK";
74 case MSG_TYPE_PLAYER_JOIN_GAME: return "MSG_TYPE_PLAYER_JOIN_GAME";
75 case MSG_TYPE_FINISH_GAME: return "MSG_TYPE_FINISH_GAME";
76 default: return "Unknown";
77 }
78}
Note: See TracBrowser for help on using the repository browser.