forked from kevinbchen/cspspserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameServer.h
More file actions
213 lines (162 loc) · 3.66 KB
/
Copy pathGameServer.h
File metadata and controls
213 lines (162 loc) · 3.66 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
#pragma once
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <errno.h>
#include <math.h>
#include <sstream>
#ifdef _WIN32
#include <winsock.h>
#define socklen_t int
#else
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
#include "Packet.h"
#include "Person.h"
#include "Vector2D.h"
#include "TileMap.h"
#include "UdpManager.h"
#include "Collision.h"
#include "Bullet.h"
#include "HttpManager.h"
#include "Grid.h"
#define VERSION 1.51f
#define NETVERSION 9
#define NONE -1
#define T 0
#define CT 1
#define TIE 2
#define ON 0
#define OFF 1
#define FREEZETIME 0
#define STARTED 1
#define MAXFILESIZE 400
class UdpManager;
struct MapInfo {
char name[256];
int type;
};
class GameServer
{
public:
// Callback functions invoked when mPeople or mBannedPeople is updated, respectively
std::function<void()> mOnPlayerListUpdate;
std::function<void()> mOnBanListUpdate;
bool mHasError;
//string mOutput;
std::stringstream mOutStream;
#ifdef _WIN32
WSADATA wsaData; // Windows socket
#endif
int sock, length;
socklen_t fromlen;
struct sockaddr_in server;
struct sockaddr_in from;
char buffer[4096];
//char mHTTPBuffer[4096];
HttpManager* mHttpManager;
//int websock;
//struct sockaddr_in webserver;
std::string ipaddress;
int mPort;
std::string mInput;
float mCursorTimer;
std::vector<MapInfo> mMapCycle;
int mMapIndex;
float mMapTime;
float mMapTimer;
int mMapTextSize;
int mMapImageSize;
int mMapOverviewSize;
FILE *mMapTextFile;
FILE *mMapImageFile;
FILE *mMapOverviewFile;
int mGameType;
int mRoundFreezeTime;
int mRoundTime;
int mRoundEndTime;
int mBuyTime;
int mRespawnTime;
int mSpawnGunIndex;
int mInvincibleTime;
float mLastRoundTime;
float mRoundTimer;
float mRoundEndTimer;
float mBuyTimer;
int mRoundState;
int mNumRounds;
int mNumCTWins;
int mNumTWins;
int mNumFlags[2];
float mFlagX[2];
float mFlagY[2];
bool mIsFlagHome[2];
Person* mFlagHolder[2];
int mRoundBit;
int mNumGuns;
UdpManager* mUdpManager;
std::vector<Person*> mPeople;
std::vector<GunObject*> mGunObjects;
std::vector<Bullet*> mBullets;
//Person* mPlayer;
TileMap* mMap;
Grid* mGrid;
Gun mGuns[28];
int mNumCTs;
int mNumTs;
int mNumRemainingCTs;
int mNumRemainingTs;
int mNumPlayers;
int mWinner;
float mTime;
int mPlayerCounter;
int mGunCounter;
int mBulletCounter;
int mChatCounter;
int ackcounter;
float mPingTimer;
bool mUpdating;
float mUpdateTimer;
float mSendMovementTimer;
char* mName;
char mMapName[32];
int mNumMaxPlayers;
int mFriendlyFire;
int mAutoBalance;
int mAllTalk;
float mTimeMultiplier;
std::vector<char*> mBannedPeople;
std::vector<char*> mAdmins;
GameServer();
~GameServer();
void Init();
void Update(float dt);
void CheckCollisions();
void CheckPlayerCollisions(Person* player);
void HandlePacket(Packet &packet, Connection* connection, sockaddr_in from, bool sendack = true);
void ResetRound(bool fullreset = false);
void RespawnPlayer(Person* player, int x, int y);
void UpdateScores(Person* attacker, Person* victim, Gun* weapon);
void CleanUp();
int Register();
char* GetConfig(const char *location, char searchstr[], int length = 32);
Person* GetPerson(int id);
int GetPlayerId();
int GetGunId();
void Buy(Person* player, int index);
void Explode(Grenade* grenade);
void HandleInput(char* input, bool remote = false);
bool LoadMap(char* mapname, int maptype);
void RemovePerson(Person* player);
std::string GetPersonName(Person* player);
//bool ReadHTTP(char* string);
char* DecodeText(char* buffer, char* text);
void Kick(char* name);
void Ban(char* name);
void Unban(char* name);
void Hash();
};