Ejemplo n.º 1
0
        public void HelloAgain(byte pid, string nick, string userId, 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.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;

            var 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.Game.Id, true);
            senderRpc.PlayerSettings(pi.Id, pi.InvertedTable, pi.IsSpectator);
            // Notify everybody of the newcomer
            _state.Broadcaster.NewPlayer(pi.Id, nick, userId, pkey, pi.InvertedTable, pi.IsSpectator);
            // Add everybody to the newcomer
            foreach (var player in _state.Players.Where(x => x.Id != pi.Id))
            {
                senderRpc.NewPlayer(player.Id, player.Nick, player.UserId, player.Pkey, player.InvertedTable, player.IsSpectator);
            }
            // Notify the newcomer of some shared settings
            senderRpc.Settings(_gameSettings.UseTwoSidedTable, _gameSettings.AllowSpectators, _gameSettings.MuteSpectators);
            foreach (var player in _state.Players)
            {
                senderRpc.PlayerSettings(player.Id, player.InvertedTable, player.IsSpectator);
            }
            // Add it to our lists
            pi.Connected = true;
            pi.ResetSocket(_sender);
            pi.Connected = true;
            _state.UpdateDcPlayer(pi.Nick, false);
            _state.Broadcaster.RefreshTypes();
            senderRpc.Start();
        }
Ejemplo n.º 2
0
 internal void OnDisconnect(bool report)
 {
     lock (this)
     {
         if (Connected == false)
         {
             return;
         }
         this.Connected = false;
     }
     this.TimeDisconnected = DateTime.Now;
     if (this.SaidHello)
     {
         new Broadcaster(_state).PlayerDisconnect(Id);
     }
     if (report && _state.IsLocal == false && _state.Handler.GameStarted && this.IsSpectator == false)
     {
         _state.UpdateDcPlayer(this.Nick, true);
     }
 }