void OnControllerIntroductionCallback(CClientSocket ClientSocket, int ConnectionIndex, byte[] arguments)
        {
            SControllerIntroduction ControllerIntroduction = (SControllerIntroduction)CSerialization.Deserialize <SControllerIntroduction>(arguments);

            SControllerAnswer ControllerAnswer = new SControllerAnswer
            {
                IsAuthorized = false,
                key          = -1
            };

            SConnection Connection = Connections[ConnectionIndex];

            if (ControllerIntroduction.Password != Program.ControllerPassword)
            {
                //Tell the controller that password was not accepted
                Connection.ClientSocket.SendPacket <SControllerAnswer>((byte)EControllerPackets.Introduction, ControllerAnswer);

                //At this stage the password is not valid, so we disconnect the invalid controller
                ClientSocket.Disconnect();
                return;
            }

            int key = GenerateKeyForController();

            //Authorize connection
            SControllerInformation ControllerInformation = (SControllerInformation)Connection.Information;

            ControllerInformation.IsAuthorized = true;
            ControllerInformation.Key          = key;
            Connection.Information             = (object)ControllerInformation;
            Connections[ConnectionIndex]       = Connection;

            //Key for controlling clients
            ControllerAnswer.key          = key;
            ControllerAnswer.IsAuthorized = true;

            //Tell the controller that he is authorized
            Connection.ClientSocket.SendPacket <SControllerAnswer>((byte)EControllerPackets.Introduction, ControllerAnswer);
        }
Exemple #2
0
        void PacketIntroductionResponse(byte[] arguments)
        {
            SControllerAnswer ControllerAnswer = CSerialization.Deserialize <SControllerAnswer>(arguments);

            if (ControllerAnswer.IsAuthorized)
            {
                if (OnConnectionAuthorized != null)
                {
                    OnConnectionAuthorized.Invoke();
                }
            }
            else
            {
                if (OnConnectionAuthorizationFailed != null)
                {
                    OnConnectionAuthorizationFailed.Invoke();
                }
            }

            if (OnUpdateKey != null)
            {
                OnUpdateKey.Invoke(ControllerAnswer.key);
            }
        }