Beispiel #1
0
        protected static async void DoLogin()
        {
            int    Sender   = Convert.ToInt32(ConfigurationManager.AppSettings["Sender"]);
            string UUID     = ConfigurationManager.AppSettings["UUID"];
            string UserId   = ConfigurationManager.AppSettings["UserId"];
            string Password = ConfigurationManager.AppSettings["Password"];

            WebSocketLoginMessage login = new WebSocketLoginMessage()
            {
                Msg      = "ClientLogin",
                Sender   = Sender,
                UUID     = UUID,
                UserId   = UserId,
                Password = Password
            };

            DoLog(string.Format("Logging user {0}", UserId));

            string strMsg = JsonConvert.SerializeObject(login, Newtonsoft.Json.Formatting.None,
                                                        new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            DoLog(string.Format("Sending: {0}", strMsg));


            byte[] msgArray = Encoding.ASCII.GetBytes(strMsg);

            ArraySegment <byte> bytesToSend = new ArraySegment <byte>(msgArray);

            await SubscriptionWebSocket.SendAsync(bytesToSend, WebSocketMessageType.Text, true,
                                                  CancellationToken.None);
        }
Beispiel #2
0
        private static void ProcessLoginClient(string[] param)
        {
            if (param.Length == 4)
            {
                WebSocketLoginMessage login = new WebSocketLoginMessage()
                {
                    Msg      = "ClientLogin",
                    Sender   = 0,
                    UserId   = param[1],
                    UUID     = param[2],
                    Password = param[3]
                };

                string strMsg = JsonConvert.SerializeObject(login, Newtonsoft.Json.Formatting.None,
                                                            new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });

                DoSend(strMsg);
            }
            else
            {
                DoLog(string.Format("Missing mandatory parameters for LoginClient message"));
            }
        }
Beispiel #3
0
        private static void LoginClient(string userId, string UUID, string password)
        {
            WebSocketLoginMessage login = new WebSocketLoginMessage()
            {
                Msg      = "ClientLogin",
                Sender   = 0,
                UserId   = userId,
                UUID     = UUID,
                Password = password
            };

            string strMsg = JsonConvert.SerializeObject(login, Newtonsoft.Json.Formatting.None,
                                                        new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            DoSend(strMsg);
        }
        protected virtual void ProcessClientLoginMock(IWebSocketConnection socket, string m)
        {
            WebSocketLoginMessage wsLogin = JsonConvert.DeserializeObject <WebSocketLoginMessage>(m);


            UserRecord loggedUser = UserRecords.Where(x => x.UserId == wsLogin.UserId).FirstOrDefault();

            DoLog(string.Format("Incoming Login request for user {0}", wsLogin.UUID), MessageType.Information);

            if (loggedUser != null)
            {
                ClientLoginResponse resp = new ClientLoginResponse()
                {
                    Msg          = "ClientLoginResponse",
                    Sender       = wsLogin.Sender,
                    UUID         = wsLogin.UUID,
                    UserId       = wsLogin.UserId,
                    JsonWebToken = _TOKEN
                };


                DoLog(string.Format("user {0} Successfully logged in", wsLogin.UUID), MessageType.Information);
                UserLogged = true;
                DoSend <ClientLoginResponse>(socket, resp);
            }
            else
            {
                ClientReject reject = new ClientReject()
                {
                    Msg          = "ClientReject",
                    Sender       = wsLogin.Sender,
                    UUID         = wsLogin.UUID,
                    UserId       = wsLogin.UserId,
                    RejectReason = string.Format("Invalid user or password")
                };

                DoLog(string.Format("user {0} Rejected because of wrong user or password", wsLogin.UUID), MessageType.Information);
                DoSend <ClientReject>(socket, reject);
                socket.Close();
            }
        }