Example #1
0
 public MessageHandlerChain(IServerHandle server)
 {
     _messageHandler =
         new RegularMessasgeHandler(server,
                                    new AuthMessageHandler(server,
                                                           new LogoutMessageHandler(server, null)));
 }
Example #2
0
 public WebSocketServerHandle(IServerHandle handle)
 {
     m_handle = handle;
 }
 public AuthMessageHandler(IServerHandle server, MessageHandler successor) : base(server, successor)
 {
 }
Example #4
0
 public MessageHandler(IServerHandle server, MessageHandler successor)
 {
     _successor  = successor;
     this.server = server;
 }
Example #5
0
        public static void Handle(object sender, string data)
        {
            ServerHandle  server = new ServerHandle();
            IServerHandle ish    = (IServerHandle)server;
            TCPHelper     helper = (TCPHelper)sender;

            string[] d = Data_Init(data);
            switch (d[0])
            {
            case "LOGIN":
                LoginContract login = null;
                try
                {
                    login = WTalk.Helpers.DataHelpers.DeXMLSer <LoginContract>(d[1]);
                }
                catch { }
                LoginCallBack callBack = ish.Login(helper.tcpClient, login);
                if (ShowOnServerWindow != null)
                {
                    if (callBack.LoginStatus == Status.Yes)
                    {
                        UserArgs args = new UserArgs
                        {
                            IP = helper.tcpClient.Client.RemoteEndPoint.ToString(),
                            Id = login.UserId
                        };
                        string log = string.Format("{0}-->Login Success", helper.tcpClient.Client.RemoteEndPoint.ToString());
                        ShowOnServerWindow(null, log);
                        if (LoginHandler != null)
                        {
                            LoginHandler(null, args);
                        }
                    }
                    else
                    {
                        string log = string.Format("{0}-->Login Fail", helper.tcpClient.Client.RemoteEndPoint.ToString());
                        ShowOnServerWindow(null, log);
                    }
                }
                string msg = string.Format("LOGINCALLBACK@{0}", WTalk.Helpers.DataHelpers.XMLSer <LoginCallBack>(callBack));
                helper.SendMessage(msg);
                break;

            case "SIGNUP":
                SignupContract signup = null;
                try
                {
                    signup = DataHelpers.DeXMLSer <SignupContract>(d[1]);
                }
                catch { }
                SignUpCallBack signUpCallBack = ish.Signup(signup);
                if (ShowOnServerWindow != null)
                {
                    string log = string.Format("{0}-->Signup:{1}", helper.tcpClient.Client.RemoteEndPoint.ToString(), signUpCallBack.MoreMsg);
                    //if (callBack.LoginStatus == Status.Yes)
                    //{
                    //    string log = string.Format("{0}-->Signup", helper.tcpClient.Client.RemoteEndPoint.ToString());
                    //    ShowOnServerWindow(null, log);
                    //}
                    //else
                    //{
                    //    string log = string.Format("{0}-->Login Fail", helper.tcpClient.Client.RemoteEndPoint.ToString());
                    //    ShowOnServerWindow(null, log);
                    //}
                    ShowOnServerWindow(null, log);
                }
                helper.SendMessage(string.Format("SIGNUPCALLBACK@{0}", DataHelpers.XMLSer <SignUpCallBack>(signUpCallBack)));
                break;

            case "LOGOUT":
                //string logoutlog = string.Format("{0}-->登出", helper.tcpClient.Client.RemoteEndPoint.ToString());
                //if(ShowOnServerWindow != null)
                //{
                //    ShowOnServerWindow(null, logoutlog);
                //}
                break;

            case "SEARCH":
                SearchContract search = null;
                try
                {
                    search = DataHelpers.DeXMLSer <SearchContract>(d[1]);
                    SearchCallBack back = ish.Search(search);
                    helper.SendMessage(string.Format("SEARCHCALLBACK@{0}", DataHelpers.XMLSer <SearchCallBack>(back)));
                }
                catch
                {
                }
                break;

            case "ADD":
                AddContract add = null;
                try
                {
                    add = DataHelpers.DeXMLSer <AddContract>(d[1]);
                    AddComfirmArgs args = ish.Add(add);
                    if (args.IP != "Offline")
                    {
                        AddHandler(null, args);
                    }
                }
                catch
                {
                    break;
                }
                break;

            case "REMOVE":
                RemoveContract remove = null;
                try
                {
                    remove = DataHelpers.DeXMLSer <RemoveContract>(d[1]);
                    ish.RemoveFriends(remove);
                    if (RemoveFriendHandler != null)
                    {
                        RemoveFriendHandler(null, remove);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                break;

            case "TALK":
                TalkContract talk = new TalkContract();
                try
                {
                    talk = DataHelpers.DeXMLSer <TalkContract>(d[1]);
                    if (TalkHandler != null)
                    {
                        TalkHandler(null, talk);
                    }
                }
                catch
                {
                }
                break;

            case "ADDCONFIRMCALLBACK":
                AddConfirmCallBack accb        = null;
                AddCallBack        addCallBack = null;
                try
                {
                    accb        = DataHelpers.DeXMLSer <AddConfirmCallBack>(d[1]);
                    addCallBack = ish.AddComfirm(accb);
                    if (UpdateFriendListHandler != null)
                    {
                        UpdateFriendListHandler(null, addCallBack);
                    }
                }
                catch
                {
                    break;
                }
                break;

            default:
                break;
            }
        }
Example #6
0
 public LogoutMessageHandler(IServerHandle server, MessageHandler successor) : base(server, successor)
 {
 }
Example #7
0
 public RegularMessasgeHandler(IServerHandle server, MessageHandler successor) : base(server, successor)
 {
 }