-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathClientNetMessage.h
138 lines (105 loc) · 2.79 KB
/
ClientNetMessage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef CLIENTNETMESSAGE_H
#define CLIENTNETMESSAGE_H
#ifdef _WIN32
#pragma once
#pragma warning(disable : 4100) // unreferenced formal parameter
#pragma warning(disable : 4514) // unreferenced inline function has been removed
#endif
#include "inetmessage.h"
#include "protocol.h"
#include "checksum_crc.h"
#include "tier0/dbg.h"
class bf_read;
class bf_write;
#define DECLARE_CLIENTNETMESSAGE( msgtype ) \
public: \
int ReadFromBuffer( bf_read * buffer ); \
int WriteToBuffer( bf_write * buffer ); \
void Clear(); \
const char *ToString(); \
static int GetType() { return msgtype; }; \
static const char *GetName() { return #msgtype; };
class CNetMessage : public INetMessage
{
public:
CNetMessage() { m_bReliable = 0; m_bOwnData = false; };
virtual ~CNetMessage() {};
void SetReliable( bool state = true) {m_bReliable = state;};
bool IsReliable() { return m_bReliable; };
bool IsConnectionless() { return false;};
virtual const char *ToString() { return "Unknown CNetMessage"; };
public:
bool m_bReliable; // true if message should be send reliable
bool m_bOwnData; // true if message object uses dynamic allocated memory
};
class CLC_SendFile : public CNetMessage
{
DECLARE_CLIENTNETMESSAGE( clc_sendfile );
CLC_SendFile(CRC32_t fileCRC)
{
m_bReliable = true;
m_bOwnData = false;
m_FileCRC = fileCRC;
}
public:
CRC32_t m_FileCRC; // CRC of file to send
};
class CLC_Move : public CNetMessage
{
DECLARE_CLIENTNETMESSAGE( clc_move );
CLC_Move( int numBackup, int numNew, int length, unsigned char * data)
{
m_bReliable = true;
m_bOwnData = false;
m_nNumBackupCommands = numBackup;
m_nNumNewCommands = numNew;
m_nLength = length; // in bits
m_Data = data;
}
public:
int m_nNumBackupCommands;
int m_nNumNewCommands;
int m_nLength;
unsigned char *m_Data;
};
class CLC_StringCmd : public CNetMessage
{
DECLARE_CLIENTNETMESSAGE( clc_stringcmd );
CLC_StringCmd(const char *command)
{
Assert( command );
m_szClientCommand = (char*)command;
m_bReliable = true;
m_bOwnData = false;
};
public:
char *m_szClientCommand;
};
class CLC_Delta : public CNetMessage
{
DECLARE_CLIENTNETMESSAGE( clc_delta );
CLC_Delta( int deltaSequeenceNr );
public:
int m_nSequenceNumber;
};
class CLC_VoiceData : public CNetMessage
{
DECLARE_CLIENTNETMESSAGE( clc_voicedata );
CLC_VoiceData( unsigned char *data, int length )
{
Assert( data );
m_Data = data;
m_nLength = length;
m_bReliable = false;
m_bOwnData = false;
};
public:
int m_nLength;
unsigned char *m_Data;
};
#endif // CLIENTNETMESSAGE_H