public void HelloAgain(byte pid, string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, false)) { return; } // Make sure the pid is one that exists var pi = State.Instance.GetPlayer(pid); if (pi == null) { ErrorAndCloseConnection(L.D.ServerMessage__CanNotReconnectFirstTimeConnecting); return; } // Make sure the pkey matches the pkey for the pid if (pi.Pkey != pkey) { ErrorAndCloseConnection(L.D.ServerMessage__PublicKeyDoesNotMatch); return; } // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); pi.Rpc = senderRpc; string software = client + " (" + clientVer + ')'; // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } pi.SaidHello = true; // welcome the player and assign them their side senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, true); senderRpc.PlayerSettings(pi.Id, pi.InvertedTable, pi.IsSpectator); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey, pi.InvertedTable, pi.IsSpectator); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) { senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey, player.InvertedTable, player.IsSpectator); } // Notify the newcomer of some shared settings senderRpc.Settings(_gameSettings.UseTwoSidedTable, _gameSettings.AllowSpectators, _gameSettings.MuteSpectators); foreach (PlayerInfo player in State.Instance.Players) { senderRpc.PlayerSettings(player.Id, player.InvertedTable, player.IsSpectator); } // Add it to our lists pi.Connected = true; pi.ResetSocket(_sender); pi.Connected = true; State.Instance.UpdateDcPlayer(pi.Nick, false); _broadcaster.RefreshTypes(); senderRpc.Start(); }
public void HelloAgain(byte pid, string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, false)) { return; } // Make sure the pid is one that exists var pi = State.Instance.GetPlayer(pid); if (pi == null) { ErrorAndCloseConnection("You can't reconnect, because you've never connected in the first place."); return; } // Make sure the pkey matches the pkey for the pid if (pi.Pkey != pkey) { ErrorAndCloseConnection("The public key you sent does not match the one on record."); return; } // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); pi.Rpc = senderRpc; string software = client + " (" + clientVer + ')'; // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } pi.SaidHello = true; senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, true); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) { senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey); } // Notify the newcomer of some shared settings senderRpc.Settings(_gameSettings.UseTwoSidedTable); foreach (PlayerInfo player in State.Instance.Players) { senderRpc.PlayerSettings(player.Id, player.InvertedTable); } // Add it to our lists pi.Connected = true; pi.ResetSocket(_sender); pi.Connected = true; _broadcaster.RefreshTypes(); senderRpc.Start(); }
public ServerSocket(TcpClient client, Server server) { client.Client.SendTimeout = 4000; this.Setup(client, new ServerMessageProcessor()); Server = server; LastPingTime = DateTime.Now; Handler = new Handler(server.Context); Rpc = new BinarySenderStub(this); Serializer = new BinaryParser(this); }
public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password, bool spectator) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, spectator)) { return; } // Check if we accept new players if (!_acceptPlayers) { ErrorAndCloseConnection("This game is already started and is no longer accepting new players."); return; } // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); string software = client + " (" + clientVer + ')'; var pi = State.Instance.GetClient(_sender); pi.Setup(_playerId++, nick, pkey, senderRpc, software, spectator); // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } pi.SaidHello = true; senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, _gameStarted || spectator); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) { senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey); } // Notify the newcomer of some shared settings senderRpc.Settings(_gameSettings.UseTwoSidedTable); foreach (PlayerInfo player in State.Instance.Players) { senderRpc.PlayerSettings(player.Id, player.InvertedTable); } // Add it to our lists _broadcaster.RefreshTypes(); if (_gameStarted || spectator) { senderRpc.Start(); } }
internal void Kick(string message, params object[] args) { var mess = string.Format(message, args); this.Connected = false; this.TimeDisconnected = DateTime.Now; var rpc = new BinarySenderStub(this.Socket, State.Instance.Handler); rpc.Kick(mess); Socket.Disconnect(); if (SaidHello) { new Broadcaster(State.Instance.Handler) .Error(string.Format("Player {0} was kicked: {1}", Nick, mess)); } SaidHello = false; }
internal void Kick(bool report, string message, params object[] args) { var mess = string.Format(message, args); this.Connected = false; this.TimeDisconnected = DateTime.Now; var rpc = new BinarySenderStub(this.Socket, State.Instance.Handler); rpc.Kick(mess); //Socket.Disconnect(); Disconnect(report); if (SaidHello) { new Broadcaster(State.Instance.Handler) .Error(string.Format(L.D.ServerMessage__PlayerKicked, Nick, mess)); } SaidHello = false; }
public void HelloAgain(byte pid, string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, false)) return; // Make sure the pid is one that exists var pi = State.Instance.GetPlayer(pid); if (pi == null) { ErrorAndCloseConnection(L.D.ServerMessage__CanNotReconnectFirstTimeConnecting); return; } // Make sure the pkey matches the pkey for the pid if (pi.Pkey != pkey) { ErrorAndCloseConnection(L.D.ServerMessage__PublicKeyDoesNotMatch); return; } // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); pi.Rpc = senderRpc; string software = client + " (" + clientVer + ')'; // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } pi.SaidHello = true; // welcome the player and assign them their side senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, true); senderRpc.PlayerSettings(pi.Id, pi.InvertedTable, pi.IsSpectator); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey, pi.InvertedTable, pi.IsSpectator); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey, player.InvertedTable, player.IsSpectator); // Notify the newcomer of some shared settings senderRpc.Settings(_gameSettings.UseTwoSidedTable, _gameSettings.AllowSpectators, _gameSettings.MuteSpectators); foreach (PlayerInfo player in State.Instance.Players) senderRpc.PlayerSettings(player.Id, player.InvertedTable, player.IsSpectator); // Add it to our lists pi.Connected = true; pi.ResetSocket(_sender); pi.Connected = true; State.Instance.UpdateDcPlayer(pi.Nick, false); _broadcaster.RefreshTypes(); senderRpc.Start(); }
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 BinarySenderStub(_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 BinarySenderStub(_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 BinarySenderStub(_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 BinarySenderStub(_sender, this); rpc.Error(string.Format("Incompatible game version. This server is hosting game version {0}.", _gameVersion)); 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 BinarySenderStub(_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(); }
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, string password, bool spectator) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, spectator)) return; if (spectator && State.Instance.Engine.Game.Spectators == false) { ErrorAndCloseConnection(L.D.ServerMessage__SpectatorsNotAllowed); return; } // Check if we accept new players if (!_acceptPlayers && spectator == false) { ErrorAndCloseConnection(L.D.ServerMessage__GameStartedNotAcceptingNewPlayers); return; } State.Instance.HasSomeoneJoined = true; // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); string software = client + " (" + clientVer + ')'; var pi = State.Instance.GetClient(_sender); pi.Setup(_playerId++, nick, pkey, senderRpc, software, spectator); // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } // decide players side of table; before saying hello so new player not included short aPlayers = (short)State.Instance.Players.Count(x => !x.InvertedTable); short bPlayers = (short)State.Instance.Players.Count(x => x.InvertedTable); if (aPlayers > bPlayers) pi.InvertedTable = true; if (spectator) pi.InvertedTable = false; pi.SaidHello = true; // Welcome newcomer and asign them their side senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, _gameStarted); senderRpc.PlayerSettings(pi.Id, pi.InvertedTable, pi.IsSpectator); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey, pi.InvertedTable, spectator); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey, player.InvertedTable, player.IsSpectator); // Notify the newcomer of table sides senderRpc.Settings(_gameSettings.UseTwoSidedTable, _gameSettings.AllowSpectators, _gameSettings.MuteSpectators); // Add it to our lists _broadcaster.RefreshTypes(); if (_gameStarted) { senderRpc.Start(); } else { if (State.Instance.Engine.IsLocal != false) return; var mess = new GameMessage(); // don't send if we join our own room...that'd be annoying if (nick.Equals(State.Instance.Engine.Game.HostUserName, StringComparison.InvariantCultureIgnoreCase)) return; mess.Message = string.Format("{0} has joined your game", nick); mess.Sent = DateTime.Now; mess.SessionId = State.Instance.Engine.Game.Id; mess.Type = GameMessageType.Event; new Octgn.Site.Api.ApiClient().GameMessage(State.Instance.Engine.ApiKey, mess); } }
public void HelloAgain(byte pid, string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId,Version gameVer, string password) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, false)) return; // Make sure the pid is one that exists var pi = State.Instance.GetPlayer(pid); if (pi == null) { ErrorAndCloseConnection("You can't reconnect, because you've never connected in the first place."); return; } // Make sure the pkey matches the pkey for the pid if (pi.Pkey != pkey) { ErrorAndCloseConnection("The public key you sent does not match the one on record."); return; } // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); pi.Rpc = senderRpc; string software = client + " (" + clientVer + ')'; // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } pi.SaidHello = true; senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, true); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x=>x.Id != pi.Id)) senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey); // Notify the newcomer of some shared settings senderRpc.Settings(_gameSettings.UseTwoSidedTable); foreach (PlayerInfo player in State.Instance.Players) senderRpc.PlayerSettings(player.Id, player.InvertedTable); // Add it to our lists pi.Connected = true; pi.ResetSocket(_sender); pi.Connected = true; _broadcaster.RefreshTypes(); senderRpc.Start(); }
internal void Kick(bool report, string message, params object[] args) { var mess = string.Format(message, args); this.Connected = false; this.TimeDisconnected = DateTime.Now; var rpc = new BinarySenderStub(this.Socket,State.Instance.Handler); rpc.Kick(mess); //Socket.Disconnect(); Disconnect(report); if (SaidHello) { new Broadcaster(State.Instance.Handler) .Error(string.Format(L.D.ServerMessage__PlayerKicked, Nick, mess)); } SaidHello = false; }
public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password, bool spectator) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, spectator)) { return; } if (spectator && State.Instance.Engine.Game.Spectators == false) { ErrorAndCloseConnection(L.D.ServerMessage__SpectatorsNotAllowed); return; } // Check if we accept new players if (!_acceptPlayers && spectator == false) { ErrorAndCloseConnection(L.D.ServerMessage__GameStartedNotAcceptingNewPlayers); return; } State.Instance.HasSomeoneJoined = true; // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); string software = client + " (" + clientVer + ')'; var pi = State.Instance.GetClient(_sender); pi.Setup(_playerId++, nick, pkey, senderRpc, software, spectator); // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } // decide players side of table; before saying hello so new player not included short aPlayers = (short)State.Instance.Players.Count(x => !x.InvertedTable); short bPlayers = (short)State.Instance.Players.Count(x => x.InvertedTable); if (aPlayers > bPlayers) { pi.InvertedTable = true; } if (spectator) { pi.InvertedTable = false; } pi.SaidHello = true; // Welcome newcomer and asign them their side senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, _gameStarted); senderRpc.PlayerSettings(pi.Id, pi.InvertedTable, pi.IsSpectator); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey, pi.InvertedTable, spectator); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) { senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey, player.InvertedTable, player.IsSpectator); } // Notify the newcomer of table sides senderRpc.Settings(_gameSettings.UseTwoSidedTable, _gameSettings.AllowSpectators, _gameSettings.MuteSpectators); // Add it to our lists _broadcaster.RefreshTypes(); if (_gameStarted) { senderRpc.Start(); } else { if (State.Instance.Engine.IsLocal != false) { return; } var mess = new GameMessage(); // don't send if we join our own room...that'd be annoying if (nick.Equals(State.Instance.Engine.Game.HostUserName, StringComparison.InvariantCultureIgnoreCase)) { return; } mess.Message = string.Format("{0} has joined your game", nick); mess.Sent = DateTime.Now; mess.SessionId = State.Instance.Engine.Game.Id; mess.Type = GameMessageType.Event; new Octgn.Site.Api.ApiClient().GameMessage(State.Instance.Engine.ApiKey, mess); } }
public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password) { // One should say Hello only once if (_clients.ContainsKey(_sender)) { _clients[_sender].Rpc.Error("[Hello]You may say hello only once."); return; } // Verify password if (!string.IsNullOrWhiteSpace(_password)) { if (!password.Equals(_password)) { var rpc = new BinarySenderStub(_sender, this); rpc.Error("The password you entered was incorrect."); try { _sender.Client.Close(); _sender.Close(); } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } return; } } // Check if the versions are compatible #if(!DEBUG) if(clientVer.CompareTo(ServerVersion) < 0) //if ((clientVer.Major != ServerVersion.Major || clientVer.Minor != ServerVersion.Minor)) { var rpc = new BinarySenderStub(_sender, this); rpc.Error(string.Format("Your version of OCTGN isn't compatible with this game server. This server is accepting {0} or greater clients only. Your current version is {1}. You should update.", ServerVersion, clientVer)); 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 BinarySenderStub(_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 BinarySenderStub(_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 BinarySenderStub(_sender, this); rpc.Error(string.Format("Incompatible game version. This server is hosting game version {0}.",_gameVersion)); 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 BinarySenderStub(_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(); }
public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password, bool spectator) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, spectator)) { return; } if (spectator && State.Instance.Engine.Game.Spectators == false) { ErrorAndCloseConnection("This game doesn't allow for spectators."); return; } // Check if we accept new players if (!_acceptPlayers && spectator == false) { ErrorAndCloseConnection("This game is already started and is no longer accepting new players."); return; } State.Instance.HasSomeoneJoined = true; // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); string software = client + " (" + clientVer + ')'; var pi = State.Instance.GetClient(_sender); pi.Setup(_playerId++, nick, pkey, senderRpc, software, spectator); // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } // decide players side of table; before saying hello so new player not included short aPlayers = (short)State.Instance.Players.Count(x => !x.InvertedTable); short bPlayers = (short)State.Instance.Players.Count(x => x.InvertedTable); if (aPlayers > bPlayers) { pi.InvertedTable = true; } pi.SaidHello = true; // Welcome newcomer and asign them their side senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, _gameStarted); senderRpc.PlayerSettings(pi.Id, pi.InvertedTable, pi.IsSpectator); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey, pi.InvertedTable, spectator); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) { senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey, player.InvertedTable, player.IsSpectator); } // Notify the newcomer of table sides senderRpc.Settings(_gameSettings.UseTwoSidedTable, _gameSettings.AllowSpectators, _gameSettings.MuteSpectators); // Add it to our lists _broadcaster.RefreshTypes(); if (_gameStarted) { senderRpc.Start(); } }
public void Hello(string nick, ulong pkey, string client, Version clientVer, Version octgnVer, Guid lGameId, Version gameVer, string password,bool spectator) { if (!ValidateHello(nick, pkey, client, clientVer, octgnVer, lGameId, gameVer, password, spectator)) return; // Check if we accept new players if (!_acceptPlayers) { ErrorAndCloseConnection("This game is already started and is no longer accepting new players."); return; } // Create the new endpoint IClientCalls senderRpc = new BinarySenderStub(_sender, this); string software = client + " (" + clientVer + ')'; var pi = State.Instance.GetClient(_sender); pi.Setup(_playerId++, nick, pkey, senderRpc, software,spectator); // Check if one can switch to Binary mode if (client == ServerName) { pi.Rpc.Binary(); pi.Rpc = senderRpc = new BinarySenderStub(_sender, this); pi.Binary = true; } // decide players side of table; before saying hello so new player not included short aPlayers = (short)State.Instance.Players.Count(x => !x.InvertedTable); short bPlayers = (short)State.Instance.Players.Count(x => x.InvertedTable); if (aPlayers > bPlayers) pi.InvertedTable = true; pi.SaidHello = true; // Welcome newcomer and asign them their side senderRpc.Welcome(pi.Id, State.Instance.Engine.Game.Id, _gameStarted || spectator); senderRpc.PlayerSettings(pi.Id, pi.InvertedTable); // Notify everybody of the newcomer _broadcaster.NewPlayer(pi.Id, nick, pkey, pi.InvertedTable); // Add everybody to the newcomer foreach (PlayerInfo player in State.Instance.Players.Where(x => x.Id != pi.Id)) senderRpc.NewPlayer(player.Id, player.Nick, player.Pkey, player.InvertedTable); // Notify the newcomer of table sides senderRpc.Settings(_gameSettings.UseTwoSidedTable); // Add it to our lists _broadcaster.RefreshTypes(); if(_gameStarted || spectator) senderRpc.Start(); }
internal void Kick(string message, params object[] args) { var mess = string.Format(message, args); this.Connected = false; this.TimeDisconnected = DateTime.Now; var rpc = new BinarySenderStub(this.Socket,State.Instance.Handler); rpc.Kick(mess); Socket.Disconnect(); if (SaidHello) { new Broadcaster(State.Instance.Handler) .Error(string.Format("Player {0} was kicked: {1}", Nick, mess)); } SaidHello = false; }