Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
generals.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef __GENERALS_H__
20#define __GENERALS_H__
21
22#ifdef _WIN32
23#include <process.h>
24#endif
25//#include <wstring.h>
26//#include <dictionary.h>
27//#include <arraylist.h>
28#include "matcher.h"
29#include "global.h"
30
31#include <string>
32#include <bitset>
33#include <vector>
34#include <map>
35#include <hash_map>
36typedef std::vector<bool> MapBitSet;
37
38// =====================================================================
39// Users
40// =====================================================================
41
42// Here are the states a matcher can be in:
43typedef enum
44{
46 STATUS_INCHANNEL, // Just entered the channel
47 STATUS_WORKING, // Sent info, needs to be matched
48 STATUS_MATCHED, // Been matched, but is still in the channel
50
52{
53public:
54 GeneralsUser(void);
56
58
60
62 int color;
63
64 bool widened;
66 time_t matchStart; // when did we request a match?
67
68 // This is a ping to a designated 3rd-party server who just
69 // responds to pings. The idea is that if the game server is
70 // behind a firewall, the client will have a 1000ms ping to it,
71 // even though he might be very close. To combat this, we have
72 // clients & servers ping some 3rd-party servers & calculate a
73 // pesudo-ping based on the sum of pings server-->3rd-->client.
74 std::vector<int> pseudoPing;
76
77 unsigned int IP;
78 int NAT;
79
81
83};
84
85// =====================================================================
86// Matcher class
87// =====================================================================
88
89typedef std::map<std::string, GeneralsUser*> UserMap;
90typedef std::map<int, UserMap> LadderMap;
91
93{
94public:
97 {}
98
99 virtual void init(void);
100 virtual void checkMatches(void);
101
102 virtual void handleDisconnect( const char *reason );
103 virtual void handleRoomMessage( const char *nick, const char *message, MessageType messageType );
104 virtual void handlePlayerMessage( const char *nick, const char *message, MessageType messageType );
105 virtual void handlePlayerJoined( const char *nick );
106 virtual void handlePlayerLeft( const char *nick );
107 virtual void handlePlayerChangedNick( const char *oldNick, const char *newNick );
108 virtual void handlePlayerEnum( bool success, int gameSpyIndex, const char *nick, int flags );
109
110private:
111 LadderMap m_ladders;
112 UserMap m_nonLadderUsers1v1;
113 UserMap m_nonLadderUsers2v2;
114 UserMap m_nonLadderUsers3v3;
115 UserMap m_nonLadderUsers4v4;
116 UserMap m_nonMatchingUsers;
117
118 double computeMatchFitness(const std::string& i1, const GeneralsUser *u1, const std::string& i2, const GeneralsUser *u2);
119
120 GeneralsUser* findUser(const std::string& who);
121 GeneralsUser* findUserInLadder(const std::string& who, int ladderID);
122 GeneralsUser* findUserInAnyLadder(const std::string& who);
123 GeneralsUser* findNonLadderUser(const std::string& who);
124 GeneralsUser* findNonMatchingUser(const std::string& who);
125
126 void addUser(const std::string& who);
127 void addUserInLadder(const std::string& who, int ladderID, GeneralsUser *user);
128 void addUserInAnyLadder(const std::string& who, GeneralsUser *user);
129 void addNonLadderUser(const std::string& who, GeneralsUser *user);
130 void addNonMatchingUser(const std::string& who, GeneralsUser *user);
131
132 bool removeUser(const std::string& who);
133 GeneralsUser* removeUserInLadder(const std::string& who, int ladderID);
134 GeneralsUser* removeUserInAnyLadder(const std::string& who);
135 GeneralsUser* removeNonLadderUser(const std::string& who);
136 GeneralsUser* removeNonMatchingUser(const std::string& who);
137
138 void checkMatchesInUserMap(UserMap& userMap, int ladderID, int numPlayers, bool showPoolSize);
139
140 void dumpUsers(void);
141
142 void sendMatchInfo(std::string name1, std::string name2, std::string name3, std::string name4,
143 std::string name5, std::string name6, std::string name7, std::string name8,
144 GeneralsUser *user1, GeneralsUser *user2, GeneralsUser *user3, GeneralsUser *user4,
145 GeneralsUser *user5, GeneralsUser *user6, GeneralsUser *user7, GeneralsUser *user8,
146 int numPlayers, int ladderID);
147
148 // Command handlers for above privmsg commands (offset is the
149 // offset for the getToken() past the command token)
150 bool handleUserInfo(const char *nick, const std::string& msg);
151 bool handleUserWiden(const char *nick);
152
153 // Weights for various matching parameters
154 int weightLowPing;
155 int weightAvgPoints;
156 int totalWeight;
157
158 time_t m_nextPoolSizeAnnouncement;
159 int m_secondsBetweenPoolSizeAnnouncements;
160
161 //typedef std::vector<std::string> StringVec;
162 //StringVec mapFileList;
163}
164;
165
166// =====================================================================
167// TEST Client Matcher class
168// =====================================================================
169
171{
172public:
175 {}
176
177 virtual void init(void);
178 virtual void checkMatches(void);
179
180 virtual void handleDisconnect( const char *reason );
181 virtual void handleRoomMessage( const char *nick, const char *message, MessageType messageType );
182 virtual void handlePlayerMessage( const char *nick, const char *message, MessageType messageType );
183 virtual void handlePlayerJoined( const char *nick );
184 virtual void handlePlayerLeft( const char *nick );
185 virtual void handlePlayerChangedNick( const char *oldNick, const char *newNick );
186 virtual void handlePlayerEnum( bool success, int gameSpyIndex, const char *nick, int flags );
187
188private:
189}
190;
191
192#endif /* __GENERALS_H__ */
193
virtual void handlePlayerEnum(bool success, int gameSpyIndex, const char *nick, int flags)
virtual void handlePlayerChangedNick(const char *oldNick, const char *newNick)
virtual void checkMatches(void)
virtual void handlePlayerJoined(const char *nick)
virtual void handlePlayerLeft(const char *nick)
virtual void handleDisconnect(const char *reason)
virtual void handleRoomMessage(const char *nick, const char *message, MessageType messageType)
virtual void handlePlayerMessage(const char *nick, const char *message, MessageType messageType)
virtual ~GeneralsClientMatcher()
Definition generals.h:174
virtual void init(void)
virtual void handleDisconnect(const char *reason)
virtual void handlePlayerLeft(const char *nick)
virtual void handlePlayerMessage(const char *nick, const char *message, MessageType messageType)
virtual void handlePlayerJoined(const char *nick)
virtual ~GeneralsMatcher()
Definition generals.h:96
virtual void checkMatches(void)
Definition generals.cpp:434
virtual void handlePlayerEnum(bool success, int gameSpyIndex, const char *nick, int flags)
virtual void init(void)
Definition generals.cpp:200
virtual void handlePlayerChangedNick(const char *oldNick, const char *newNick)
virtual void handleRoomMessage(const char *nick, const char *message, MessageType messageType)
std::vector< int > pseudoPing
Definition generals.h:74
int maxPoints
Definition generals.h:57
UserStatus status
Definition generals.h:55
int maxDiscons
Definition generals.h:59
bool widened
Definition generals.h:64
GeneralsUser(void)
Definition generals.cpp:131
time_t timeToWiden
Definition generals.h:65
int minPoints
Definition generals.h:57
MapBitSet maps
Definition generals.h:80
unsigned int IP
Definition generals.h:77
time_t matchStart
Definition generals.h:66
int numPlayers
Definition generals.h:82
std::map< std::string, GeneralsUser * > UserMap
Definition generals.h:89
UserStatus
Definition generals.h:44
@ STATUS_WORKING
Definition generals.h:47
@ STATUS_INVAL
Definition generals.h:45
@ STATUS_INCHANNEL
Definition generals.h:46
@ STATUS_MATCHED
Definition generals.h:48
std::vector< bool > MapBitSet
Definition generals.h:36
std::map< int, UserMap > LadderMap
Definition generals.h:90
MSG msg
Definition patch.cpp:409
long time_t
Definition wolapi.h:436