public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid gameId, Version gameVer) { // One should say Hello only once if(clients.ContainsKey(sender)) { clients[sender].rpc.Error("[Hello]You may say hello only once."); return; } // Check if the versions are compatible #if !DEBUG if(clientVer.Major != ServerVersion.Major || clientVer.Minor != ServerVersion.Minor) { XmlSenderStub rpc = new XmlSenderStub(sender, this); rpc.Error(string.Format("Incompatible versions. This server is accepting {0}.* clients only.", ServerVersion.ToString(2))); try { sender.Client.Close(); sender.Close(); } catch { } return; } #endif // Check if we accept new players if(!acceptPlayers) { XmlSenderStub rpc = new XmlSenderStub(sender, this); rpc.Error("No more players are accepted in this game."); try { sender.Client.Close(); sender.Close(); } catch { } return; } // Check if the client wants to play the correct game if(gameId != this.gameId) { XmlSenderStub rpc = new XmlSenderStub(sender, this); rpc.Error(string.Format("Invalid game. This server is hosting another game (game id: {0}).", this.gameId)); try { sender.Client.Close(); sender.Close(); } catch { } return; } // Check if the client's major game version matches ours if(gameVer.Major != this.gameVersion.Major) { XmlSenderStub rpc = new XmlSenderStub(sender, this); rpc.Error(string.Format("Incompatible game version. This server is hosting game version {0:3}.", this.gameVersion)); try { sender.Client.Close(); sender.Close(); } catch { } return; } // Create the new endpoint IClientCalls senderRpc = new XmlSenderStub(sender, this); string software = client + " (" + clientVer.ToString() + ')'; PlayerInfo pi = new PlayerInfo(playerId++, nick, pkey, senderRpc, software); // Check if one can switch to binary mode if(client == ServerName) { pi.rpc.Binary(); pi.rpc = senderRpc = new BinarySenderStub(sender, this); pi.binary = true; } // Notify everybody of the newcomer broadcaster.NewPlayer(pi.id, nick, pkey); // Add everybody to the newcomer foreach(PlayerInfo player in clients.Values) senderRpc.NewPlayer(player.id, player.nick, player.pkey); senderRpc.Welcome(pi.id); // Notify the newcomer of some shared settings senderRpc.Settings(gameSettings.UseTwoSidedTable); foreach(PlayerInfo player in players.Values.Where(p => p.invertedTable)) senderRpc.PlayerSettings(player.id, true); // Add it to our lists clients.Add(sender, pi); players.Add(pi.id, pi); broadcaster.RefreshTypes(); }
public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer) { // One should say Hello only once if (_clients.ContainsKey(_sender)) { _clients[_sender].Rpc.Error("[Hello]You may say hello only once."); return; } // Check if the versions are compatible #if !DEBUG if (clientVer.Major != ServerVersion.Major || clientVer.Minor != ServerVersion.Minor) { var rpc = new XmlSenderStub(_sender, this); rpc.Error(string.Format("Incompatible versions. This server is accepting {0}.* clients only.", ServerVersion.ToString(2))); try { _sender.Client.Close(); _sender.Close(); } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } return; } #endif // Check if we accept new players if (!_acceptPlayers) { var rpc = new XmlSenderStub(_sender, this); rpc.Error("No more players are accepted in this game."); try { _sender.Client.Close(); _sender.Close(); } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } return; } // Check if the client wants to play the correct game if (lGameId != _gameId) { var rpc = new XmlSenderStub(_sender, this); rpc.Error(string.Format("Invalid game. This server is hosting another game (game id: {0}).", _gameId)); try { _sender.Client.Close(); _sender.Close(); } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } return; } // Check if the client's major game version matches ours if (gameVer.Major != _gameVersion.Major) { var rpc = new XmlSenderStub(_sender, this); rpc.Error(string.Format("Incompatible game version. This server is hosting game version .")); try { _sender.Client.Close(); _sender.Close(); } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } return; } // Create the new endpoint IClientCalls senderRpc = new XmlSenderStub(_sender, this); string software = client + " (" + clientVer + ')'; var pi = new PlayerInfo(_playerId++, nick, pkey, senderRpc, software); // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey); // Add everybody to the newcomer foreach (PlayerInfo player in _clients.Values) senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey); senderRpc.Welcome(pi.Id); // Notify the newcomer of some shared settings senderRpc.Settings(_gameSettings.UseTwoSidedTable); foreach (PlayerInfo player in _players.Values.Where(p => p.InvertedTable)) senderRpc.PlayerSettings(player.Id, true); // Add it to our lists _clients.Add(_sender, pi); _players.Add(pi.Id, pi); _broadcaster.RefreshTypes(); }