NewPlayer() public method

public NewPlayer ( byte id, string nick, ulong pkey, bool tableSide, bool spectator ) : void
id byte
nick string
pkey ulong
tableSide bool
spectator bool
return void
Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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();
            }
        }