-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusermessages.h
More file actions
214 lines (182 loc) · 4.95 KB
/
usermessages.h
File metadata and controls
214 lines (182 loc) · 4.95 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#ifndef USER_MESSAGES_H
#define USER_MESSAGES_H
#pragma warning(disable : 26812)
#include <eiface.h>
#include <utldict.h>
#include <utlvector.h>
#include <bitbuf.h>
#include "recipientfilter.h"
// Client dispatch function for usermessages
typedef void (*pfnUserMsgHook)(bf_read &msg);
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CUserMessage
{
public:
// byte size of message, or -1 for variable sized
int size;
const char *name;
// Client only dispatch function for message
CUtlVector<pfnUserMsgHook> clienthooks;
};
//-----------------------------------------------------------------------------
// Purpose: Interface for registering and dispatching usermessages
// Shred code creates same ordered list on client/server
//-----------------------------------------------------------------------------
class CUserMessages
{
public:
CUserMessages();
~CUserMessages();
// Returns -1 if not found, otherwise, returns appropriate index
int LookupUserMessage(const char *name);
int GetUserMessageSize(int index);
const char *GetUserMessageName(int index);
bool IsValidIndex(int index);
// Server only
void Register(const char *name, int size);
void Unregister(const char *name);
// Client only
void HookMessage(const char *name, pfnUserMsgHook hook);
bool DispatchUserMessage(int msg_type, bf_read &msg_data);
public:
CUtlDict< CUserMessage *, int > m_UserMessages;
};
extern CUserMessages *usermessages_server;
extern CUserMessages *usermessages_client;
//-----------------------------------------------------------------------------
// Message networking
//-----------------------------------------------------------------------------
enum UserMsgDest
{
MSG_UNICAST = 0, // unreliable for a single client
MSG_UNICAST_RELIABLE, // reliable for a single client
MSG_BROADCAST, // unreliable for all clients
MSG_BROADCAST_RELIABLE // reliable for all clients
};
enum UserMsgType
{
MSG_TYPE_GEIGER = 0,
MSG_TYPE_TRAIN,
MSG_TYPE_HUDTEXT,
MSG_TYPE_SAYTEXT,
MSG_TYPE_SAYTEXT2,
MSG_TYPE_TEXTMSG,
MSG_TYPE_HUDMSG,
MSG_TYPE_RESETHUD,
MSG_TYPE_GAMETITLE,
MSG_TYPE_ITEMPICKUP,
MSG_TYPE_SHOWMENU,
MSG_TYPE_SHAKE,
MSG_TYPE_FADE,
MSG_TYPE_VGUIMENU,
MSG_TYPE_RUMBLE,
MSG_TYPE_CLOSECAPTION,
MSG_TYPE_CLOSECAPTIONDIRECT,
MSG_TYPE_SENDAUDIO,
MSG_TYPE_RAWAUDIO,
MSG_TYPE_VOICEMASK,
MSG_TYPE_REQUESTSTATE,
MSG_TYPE_BARTIME,
MSG_TYPE_DAMAGE,
MSG_TYPE_RADIOTEXT,
MSG_TYPE_HINTTEXT,
MSG_TYPE_KEY,
MSG_TYPE_RELOADEFFECT,
MSG_TYPE_PLAYERANIMEVENT,
MSG_TYPE_AMMODENIED,
MSG_TYPE_UPDATERADAR,
MSG_TYPE_KILLCAM,
MSG_TYPE_MARKACHIEVEMENT,
MSG_TYPE_SPLATTER,
MSG_TYPE_MELEESLASHSPLATTER,
MSG_TYPE_MELEECLUB,
MSG_TYPE_MUDSPLATTER,
MSG_TYPE_SPLATTERCLEAR,
MSG_TYPE_MESSAGETEXT,
MSG_TYPE_TRANSITIONRESTORE,
MSG_TYPE_SPAWN,
MSG_TYPE_CREDITSLINE,
MSG_TYPE_CREDITSMSG,
MSG_TYPE_JOINLATEMSG,
MSG_TYPE_STATSCRAWLMSG,
MSG_TYPE_STATSSKIPSTATE,
MSG_TYPE_SHOWSTATS,
MSG_TYPE_BLURFADE,
MSG_TYPE_MUSICCMD,
MSG_TYPE_WITCHBLOODSPLATTER,
MSG_TYPE_ACHIEVEMENTEVENT,
MSG_TYPE_PZDMGMSG,
MSG_TYPE_ALLPLAYERSCONNECTEDGAMESTARTING,
MSG_TYPE_VOTEREGISTERED,
MSG_TYPE_DISCONNECTTOLOBBY,
MSG_TYPE_CALLVOTEFAILED,
MSG_TYPE_STEAMWEAPONSTATDATA,
MSG_TYPE_CURRENTTIMESCALE,
MSG_TYPE_DESIREDTIMESCALE,
MSG_TYPE_PZENDGAMEPANELMSG,
MSG_TYPE_PZENDGAMEPANELVOTEREGISTEREDMSG,
MSG_TYPE_PZENDGAMEVOTESTATSMSG,
MSG_TYPE_VOTESTART,
MSG_TYPE_VOTEPASS,
MSG_TYPE_VOTEFAIL
};
extern IVEngineServer *g_pEngineServer;
extern bf_write *g_pMsgBuffer;
extern const char *g_szUserMessages[];
void UserMessageBegin(UserMsgDest dest, const int nMsgType, const char *pszMessage, edict_t *pRecipient);
inline void MessageBegin(UserMsgDest dest, UserMsgType type, edict_t *pRecipient = NULL)
{
UserMessageBegin(dest, static_cast<int>(type), g_szUserMessages[type], pRecipient);
}
inline void MessageBegin(UserMsgDest dest, int type, const char *pszName, edict_t *pRecipient = NULL)
{
UserMessageBegin(dest, type, pszName, pRecipient);
}
inline void MessageBegin(IRecipientFilter *filter, UserMsgType type)
{
g_pMsgBuffer = g_pEngineServer->UserMessageBegin(filter, static_cast<int>(type), g_szUserMessages[type]);
}
inline void MessageEnd()
{
g_pEngineServer->MessageEnd();
g_pMsgBuffer = NULL;
}
inline void WriteChar(int val)
{
g_pMsgBuffer->WriteChar(val);
}
inline void WriteByte(int val)
{
g_pMsgBuffer->WriteByte(val);
}
inline void WriteShort(int val)
{
g_pMsgBuffer->WriteShort(val);
}
inline void WriteWord(int val)
{
g_pMsgBuffer->WriteWord(val);
}
inline void WriteLong(long val)
{
g_pMsgBuffer->WriteLong(val);
}
inline void WriteLongLong(int64 val)
{
g_pMsgBuffer->WriteLongLong(val);
}
inline void WriteFloat(float val)
{
g_pMsgBuffer->WriteFloat(val);
}
inline bool WriteBytes(const void *pBuf, int nBytes)
{
return g_pMsgBuffer->WriteBytes(pBuf, nBytes);
}
inline bool WriteString(const char *pStr)
{
return g_pMsgBuffer->WriteString(pStr);
}
#endif // USER_MESSAGES_H