source: network-game/common/MessageContainer.cpp@ ea3a3a9

Last change on this file since ea3a3a9 was 13a8212, checked in by Dmitry Portnoy <dmp1488@…>, 9 years ago

In the MessageContainer, add a field for when the message was originally sent

  • Property mode set to 100644
File size: 2.7 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->timeSent = mc.timeSent;
14 this->isAcked = mc.isAcked;
15 this->timeAcked = mc.timeAcked;
16}
17
18MessageContainer::MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr) {
19 this->clientAddr = clientAddr;
20 this->msg = msg;
21 this->timeSent = 0;
22 this->isAcked = false;
23 this->timeAcked = 0;
24}
25
26MessageContainer::~MessageContainer() {
27}
28
29NETWORK_MSG* MessageContainer::getMessage() {
30 return &msg;
31}
32
33bool MessageContainer::getAcked() {
34 return this->isAcked;
35}
36
37unsigned long long MessageContainer::getTimeSent() {
38 return this->timeSent;
39}
40
41unsigned long long MessageContainer::getTimeAcked() {
42 return this->timeAcked;
43}
44
45void MessageContainer::setAcked(bool acked) {
46 this->isAcked = acked;
47}
48
49void MessageContainer::setTimeSent(unsigned long long time) {
50 this->timeSent = time;
51}
52
53void MessageContainer::setTimeAcked(unsigned long long time) {
54 this->timeAcked = time;
55}
56
57string MessageContainer::getMsgTypeString(int msgType) {
58 switch(msgType) {
59 case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
60 case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
61 case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
62 case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
63 case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
64 case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
65 case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
66 case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
67 case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
68 case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
69 case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
70 case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
71 case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
72 case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
73 case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
74 case MSG_TYPE_CREATE_GAME: return "MSG_TYPE_CREATE_GAME";
75 case MSG_TYPE_JOIN_GAME: return "MSG_TYPE_JOIN_GAME";
76 case MSG_TYPE_LEAVE_GAME: return "MSG_TYPE_LEAVE_GAME";
77 case MSG_TYPE_GAME_INFO: return "MSG_TYPE_GAME_INFO";
78 case MSG_TYPE_JOIN_GAME_SUCCESS: return "MSG_TYPE_JOIN_GAME_SUCCESS";
79 case MSG_TYPE_JOIN_GAME_FAILURE: return "MSG_TYPE_JOIN_GAME_FAILURE";
80 case MSG_TYPE_JOIN_GAME_ACK: return "MSG_TYPE_JOIN_GAME_ACK";
81 case MSG_TYPE_PLAYER_JOIN_GAME: return "MSG_TYPE_PLAYER_JOIN_GAME";
82 case MSG_TYPE_FINISH_GAME: return "MSG_TYPE_FINISH_GAME";
83 default: return "Unknown";
84 }
85}
Note: See TracBrowser for help on using the repository browser.