private void ClientSocket_OnClientConnected() { //We must announce the server-side that this is a Controller connection int controller = 1; byte[] buffer = BitConverter.GetBytes(controller); ClientSocket.SendBuffer(buffer); //We need to authorize this connection as a controller. SControllerIntroduction ControllerIntroduction = new SControllerIntroduction { Password = Program.Password }; ClientSocket.SendPacket <SControllerIntroduction>((byte)EControllerPackets.Introduction, ControllerIntroduction); }
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); }