예제 #1
0
        private void HandleLogin(DataReceivedEventArgs arg, Client client)
        {
            Exception exp = null;

            try
            {
                Message qmessage = new Message(arg);
                Logger.Log("[QueueServer] Processing " + qmessage.MessageType.String + " from " + arg.RemoteInfo);

                string module   = qmessage.PayloadValues["module"];
                string post     = qmessage.PayloadValues["post"];
                string station  = qmessage.PayloadValues["station"];
                string username = qmessage.PayloadValues["username"];
                string password = qmessage.PayloadValues["password"];

                if (!client.LoggedIn)
                {
                    client.Type     = Client.ClientTypeFromString(module);
                    client.Name     = station;
                    client.Post     = post;
                    client.UserName = username;
                    client.Password = password;

                    bool   allowed = false;
                    string reason  = "Not Allowed";
                    if (QueueRepository.CanLogin(client.Name, client.Post, out reason))
                    {
                        if (QueueRepository.Login(client.UserName, client.Password, out reason))
                        {
                            allowed = true;
                        }
                    }

                    if (allowed)
                    {
                        client.LoggedIn = true;

                        Logger.Log("[QueueServer] Logged on : " + module + " - " + client.Name + " - " + client.Post + " from: " + client.RemoteInfo);

                        // SYS|LOGIN|RES|[Result!Data]
                        string message =
                            Msg.SysLogin.Text +
                            Msg.Separator + "RES" +
                            Msg.Separator + "OK" +
                            Msg.CompDelimiter + "Identifier";

                        client.Session.Send(message);
                    }
                    else
                    {
                        // SYS|LOGIN|RES|[Result!Data]
                        string message =
                            Msg.SysLogin.Text +
                            Msg.Separator + "RES" +
                            Msg.Separator + "FAIL" +
                            Msg.CompDelimiter + reason;

                        client.Session.Send(message);
                        //client.Close();
                    }
                }
            }
            catch (AppException ex)
            {
                exp = ex;
            }
            catch (Exception ex)
            {
                exp = ex;
            }

            if (exp != null)
            {
                Logger.Log("QueueServer", exp);
            }
        }