Example #1
0
        public bool Register(string host, ushort port, string username, string password)
        {
            Connect(host, port);

            if (socket.Connected)
            {
                socket.Send(Encoding.UTF8.GetBytes(LoginExchange.Encode(LoginExchangeType.Register, username, password)));
                byte[] responseBuffer          = new byte[1024 * 2];
                int    responseSize            = socket.Receive(responseBuffer);
                LoginExchangeResponse response = LoginExchangeResponse.Decode(responseBuffer, responseSize);
                LatestLoginAttemtResponse = response.ExchangeType;
                switch (LatestLoginAttemtResponse)
                {
                case LoginExchangeResponseCode.Successful:
                    LoggedIn   = true;
                    Username   = username;
                    LoginToken = response.LoginToken;
                    return(true);

                default:
                    LoggedIn = false;
                    return(false);
                }
            }
            else
            {
                LoggedIn = false;
                return(false);
            }
        }
Example #2
0
 public ChatRoomClient(Action <CommandExchangeResponse> CommandResponseHandler)
 {
     this.CommandResponseHandler = CommandResponseHandler;
     Initialize();
     LatestLoginAttemtResponse = LoginExchangeResponseCode.GenericError;
     LoggedIn = false;
 }
Example #3
0
        public bool Connect(string host, ushort port)
        {
            try
            {
                Initialize();
                socket.Connect(host, port);

                return(true);
            }
            catch (SocketException)
            {
                LatestLoginAttemtResponse = LoginExchangeResponseCode.ConnectionError;
                return(false);
            }
        }
Example #4
0
 public static string Encode(LoginExchangeResponseCode responseCode, string loginToken = "")
 {
     return(JsonConvert.SerializeObject(new LoginExchangeResponse {
         LoginToken = loginToken, ExchangeType = responseCode
     }));
 }