private void OnMessageReceived(MessageReader message) { var flag = message.Tag; Logger.Verbose("Server got {0}.", flag); switch (flag) { case MessageFlags.HostGame: { using (var packet = MessageWriter.Get(SendOption.Reliable)) { Message13Redirect.Serialize(packet, false, _nodeProvider.Get()); _connection.Send(packet); } break; } case MessageFlags.JoinGame: { Message01JoinGame.Deserialize(message, out var gameCode, out var unknown); using (var packet = MessageWriter.Get(SendOption.Reliable)) { var endpoint = _nodeLocator.Find(GameCode.IntToGameName(gameCode)); if (endpoint == null) { Message01JoinGame.SerializeError(packet, false, DisconnectReason.GameMissing); } else { Message13Redirect.Serialize(packet, false, endpoint); } _connection.Send(packet); } break; } case MessageFlags.GetGameListV2: { // TODO: Implement. using (var packet = MessageWriter.Get(SendOption.Reliable)) { Message01JoinGame.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.NotImplemented); _connection.Send(packet); } break; } default: { Logger.Warning("Received unsupported message flag on the redirector ({0}).", flag); break; } } }
public Game Create(GameOptionsData options) { // TODO: Prevent duplicates when using server redirector using INodeProvider. var gameCode = GameCode.GenerateCode(6); var gameCodeStr = GameCode.IntToGameName(gameCode); var game = new Game(this, _nodeLocator, _publicIp, gameCode, options); if (_nodeLocator.Find(gameCodeStr) == null && _games.TryAdd(gameCode, game)) { _nodeLocator.Save(gameCodeStr, _publicIp); _logger.LogDebug("Created game with code {0} ({1}).", game.CodeStr, gameCode); return(game); } _logger.LogWarning("Failed to create game."); return(null); }