This repository was archived by the owner on Aug 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerGame.cs
More file actions
297 lines (272 loc) · 10.7 KB
/
Copy pathServerGame.cs
File metadata and controls
297 lines (272 loc) · 10.7 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
using System.Collections.Generic;
using System.Linq;
using Blaze3SDK.Blaze;
using Blaze3SDK.Blaze.GameManager;
using Blaze3SDK.Components;
using Zamboni11.Components.Blaze;
namespace Zamboni11;
public class ServerGame
{
private readonly object _lockReplicatedPlayers = new();
private SortedDictionary<string, string> toStringDictionary(MatchmakingCriteriaData matchmakingCriteriaData)
{
SortedDictionary<string, string> retList = new();
foreach (var VARIABLE in matchmakingCriteriaData.mGenericRulePrefsList)
{
retList.Add(VARIABLE.mRuleName, VARIABLE.mDesiredValues[0]);
}
return retList;
}
public ServerGame(ServerPlayer host, StartMatchmakingRequest request)
{
var gameId = Program.Database.GetNextGameId();
ReplicatedGameData = new ReplicatedGameData
{
mAdminPlayerList = new List<long>
{
host.UserIdentification.mAccountId
},
mGameAttribs = toStringDictionary(request.mCriteriaData),
mSlotCapacities = new List<ushort>
{
0, request.mCriteriaData.mGameSizeRulePrefs.mMaxPlayerCapacity
},
mEntryCriteriaMap = request.mEntryCriteriaMap,
mGameId = gameId,
mGameName = "game" + gameId,
mGameSettings = request.mGameSettings,
mGameReportingId = gameId,
mGameState = GameState.INITIALIZING,
mHostNetworkAddressList = new List<NetworkAddress>
{
host.ExtendedData.mAddress
},
mTopologyHostSessionId = (uint)host.UserIdentification.mAccountId,
mIgnoreEntryCriteriaWithInvite = true,
mMeshAttribs = new SortedDictionary<string, string>(),
mMaxPlayerCapacity = request.mCriteriaData.mGameSizeRulePrefs.mMaxPlayerCapacity,
mNetworkQosData = host.ExtendedData.mQosData,
mNetworkTopology = request.mNetworkTopology,
mPlatformHostInfo = new HostInfo
{
mPlayerId = host.UserIdentification.mAccountId,
mSlotId = 0
},
mPingSiteAlias = "qos",
mQueueCapacity = 0,
mTopologyHostInfo = new HostInfo
{
mPlayerId = host.UserIdentification.mAccountId,
mSlotId = 0
},
mTeamCapacity = new List<TeamCapacity>
{
new()
{
mTeamCapacity = 2,
mTeamId = 1,
mTeamIndex = 0
},
new()
{
mTeamCapacity = 2,
mTeamId = 2,
mTeamIndex = 1
}
},
mUUID = "game" + gameId,
mVoipNetwork = VoipTopology.VOIP_DISABLED,
mGameProtocolVersionString = request.mGameProtocolVersionString,
mXnetNonce = new byte[]
{
},
mXnetSession = new byte[]
{
}
};
ServerManager.AddServerGame(gameId, this);
}
public ServerGame(ServerPlayer host, CreateGameRequest request)
{
var gameId = Program.Database.GetNextGameId();
ReplicatedGameData = new ReplicatedGameData
{
mAdminPlayerList = new List<long>
{
host.UserIdentification.mAccountId
},
mEntryCriteriaMap = request.mEntryCriteriaMap,
mGameAttribs = request.mGameAttribs,
mGameId = gameId,
mGameName = "game" + gameId,
mGameProtocolVersionHash = GameManager.GetGameProtocolVersionHash(request.mGameProtocolVersionString),
mGameProtocolVersionString = request.mGameProtocolVersionString,
mGameReportingId = gameId,
mGameSettings = request.mGameSettings,
mGameState = GameState.INITIALIZING,
mGameTypeName = request.mGameTypeName,
mHostNetworkAddressList = new List<NetworkAddress>
{
host.ExtendedData.mAddress
},
mIgnoreEntryCriteriaWithInvite = request.mIgnoreEntryCriteriaWithInvite,
mMaxPlayerCapacity = request.mMaxPlayerCapacity,
mMeshAttribs = request.mMeshAttribs,
mNetworkQosData = host.ExtendedData.mQosData,
mNetworkTopology = GameNetworkTopology.PEER_TO_PEER_FULL_MESH, //TODO
mPersistedGameId = gameId.ToString(),
mPersistedGameIdSecret = request.mPersistedGameIdSecret,
mPingSiteAlias = "qos",
mPlatformHostInfo = new HostInfo
{
mPlayerId = host.UserIdentification.mAccountId,
mSlotId = 0
},
mTopologyHostSessionId = (uint)host.UserIdentification.mAccountId,
mPresenceMode = request.mPresenceMode,
mQueueCapacity = request.mQueueCapacity,
mServerNotResetable = request.mServerNotResetable,
mSharedSeed = gameId,
mSlotCapacities = request.mSlotCapacities,
mTeamCapacity = new List<TeamCapacity>
{
// new()
// {
// mTeamCapacity = 6,
// mTeamId = 1,
// mTeamIndex = 0
// },
// new()
// {
// mTeamCapacity = 3,
// mTeamId = 2,
// mTeamIndex = 1
// }
},
mTeamIds = request.mTeamIds,
mTopologyHostInfo = new HostInfo
{
mPlayerId = host.UserIdentification.mAccountId,
mSlotId = 0
},
mUUID = gameId.ToString(),
mVoipNetwork = VoipTopology.VOIP_DISABLED,
mXnetNonce = new byte[]
{
},
mXnetSession = new byte[]
{
}
};
ServerManager.AddServerGame(gameId, this);
}
public List<ServerPlayer> ServerPlayers { get; } = new();
public ReplicatedGameData ReplicatedGameData { get; set; }
public List<ReplicatedGamePlayer> ReplicatedGamePlayers { get; set; } = new();
public bool HasSpaceForPlayer()
{
return ReplicatedGameData.mSlotCapacities[0] > ReplicatedGamePlayers.Count;
}
private List<ushort> Capacities(string gameMode)
{
if (gameMode.Equals("3"))
return new List<ushort>
{
0, 12
};
return new List<ushort>
{
0, 2
};
}
public void AddGameParticipant(ServerPlayer serverPlayer, uint matchmakingSessionId = 0)
{
//TODO Lobby capacities?
ServerPlayers.Add(serverPlayer);
var replicatedGamePlayer = serverPlayer.ToReplicatedGamePlayer((byte)(ServerPlayers.Count - 1), ReplicatedGameData.mGameId);
ReplicatedGamePlayers.Add(replicatedGamePlayer);
ReplicatedGameData.mHostNetworkAddressList.Add(serverPlayer.ExtendedData.mAddress);
GameManagerBase.Server.NotifyGameSetupAsync(serverPlayer.BlazeServerConnection, new NotifyGameSetup
{
mGameData = ReplicatedGameData,
mGameRoster = ReplicatedGamePlayers,
mGameSetupReason = new GameSetupReason
{
MatchmakingSetupContext = new MatchmakingSetupContext
{
mFitScore = 10,
mMatchmakingResult = MatchmakingResult.SUCCESS_CREATED_GAME,
mMaxPossibleFitScore = 10,
mSessionId = matchmakingSessionId,
mUserSessionId = matchmakingSessionId
},
}
});
NotifyParticipants(new NotifyPlayerJoining
{
mGameId = ReplicatedGameData.mGameId,
mJoiningPlayer = replicatedGamePlayer
});
}
public void RemoveGameParticipant(ServerPlayer serverPlayer, PlayerRemovedReason reason)
{
//Concurrent exception
lock (_lockReplicatedPlayers)
{
ServerPlayers.Remove(serverPlayer);
var replicatedPlayerToRemove = ReplicatedGamePlayers.Find(replicatedPlayer => replicatedPlayer.mPlayerName.Equals(serverPlayer.UserIdentification.mName));
ReplicatedGamePlayers.Remove(replicatedPlayerToRemove);
}
NotifyParticipants(new NotifyPlayerRemoved
{
mPlayerRemovedTitleContext = 0,
mGameId = ReplicatedGameData.mGameId,
mPlayerId = serverPlayer.UserIdentification.mBlazeId,
mPlayerRemovedReason = reason
});
}
public void NotifyParticipants(NotifyGamePlayerStateChange playerStateChange)
{
foreach (var serverPlayer in ServerPlayers.ToList()) GameManagerBase.Server.NotifyGamePlayerStateChangeAsync(serverPlayer.BlazeServerConnection, playerStateChange);
}
public void NotifyParticipants(NotifyPlayerJoinCompleted playerJoinCompleted)
{
foreach (var serverPlayer in ServerPlayers.ToList()) GameManagerBase.Server.NotifyPlayerJoinCompletedAsync(serverPlayer.BlazeServerConnection, playerJoinCompleted);
}
public void NotifyParticipants(NotifyPlayerRemoved playerRemoved)
{
foreach (var serverPlayer in ServerPlayers.ToList()) GameManagerBase.Server.NotifyPlayerRemovedAsync(serverPlayer.BlazeServerConnection, playerRemoved);
}
private void NotifyParticipants(NotifyPlayerJoining playerJoining)
{
foreach (var serverPlayer in ServerPlayers.ToList()) GameManagerBase.Server.NotifyPlayerJoiningAsync(serverPlayer.BlazeServerConnection, playerJoining);
}
private SortedDictionary<string, string> VsGameAttribs()
{
return new SortedDictionary<string, string>
{
{ "CreatedPlays", "1" },
{ "Fighting", "1" },
{ "Injuries", "1" },
{ "OSDK_categoryId", "0" },
{ "OSDK_coop", "1" },
{ "OSDK_gameMode", "1" },
{ "OSDK_matchupHash", "0" },
{ "OSDK_roomId", "0" },
{ "OSDK_rosterURL", "" },
{ "OSDK_rosterVersion", "1LuRFj1HEciO3Cn22f1PWbzP3Sf6vF1dzeTg4HOr3l1FcL9G1bjJEj" },
{ "OSDK_sponsoredEventId", "0" },
{ "Penalties", "1" },
{ "PeriodLength", "5" },
{ "Rules", "1" }
};
}
public override string ToString()
{
return "Players: " +
string.Join(", ", ServerPlayers.Select(serverPlayer => serverPlayer.UserIdentification.mName)) +
" gameId:" + ReplicatedGameData.mGameId +
" state: " + ReplicatedGameData.mGameState +
" type (1 vs game 2 shootout, 3 otp): " + ReplicatedGameData.mGameAttribs["OSDK_gameMode"];
}
}