Пример #1
0
        private void ParseCommand(string xml)
        {
#if DEBUG
            Debug.Log("==================================================");
            if (peer.Info != null)
            {
                UserInfo userInfo = this.peer.Info as UserInfo;
                Debug.Log("Response From: {0}", userInfo.Name);
            }
            else
            {
                Debug.Log("Response From: {0}", peer.GetRemoteIP());
            }
            Debug.Log("Response: '{0}'", xml);
            Debug.Log("==================================================");
#endif

            // Parse Xml Command
            XmlRequest xmlRequest = null;
            try {
                xmlRequest = new XmlRequest(xml);
                xmlRequest.Parse();
            } catch (Exception e) {
                Debug.Log("Parse Xml: {0}", e.Message);
                return;
            }

            // Protocol Commands
            switch (xmlRequest.FirstTag)
            {
            case "login":
                Login login = new Login(peer, xmlRequest);
                if (login.Authentication() == true && login.User != null)
                {
                    // Add to Known User
                    P2PManager.AddPeer(login.User, peer);

                    // Start Login Event
                    CmdManager.StartLoginEvent(peer, login.User);
                }
                else
                {
                    Debug.Log("Auth Failed: {0}", peer.GetRemoteIP());
                }
                break;

            case "quit":
                CmdManager.StartQuitEvent(peer, xmlRequest);
                break;

            case "error":
                CmdManager.StartErrorEvent(peer, xmlRequest);
                break;

            case "get":
                CmdManager.StartGetEvent(peer, xmlRequest);
                break;

            case "ask":
                CmdManager.StartAskEvent(peer, xmlRequest);
                break;

            case "accept":
                CmdManager.StartAcceptEvent(peer, xmlRequest);
                break;

            case "snd":
                CmdManager.StartSndEvent(peer, xmlRequest);
                break;

            case "snd-start":
                CmdManager.StartSndStartEvent(peer, xmlRequest);
                break;

            case "snd-end":
                CmdManager.StartSndEndEvent(peer, xmlRequest);
                break;

            case "snd-abort":
                CmdManager.StartSndAbortEvent(peer, xmlRequest);
                break;

            case "recv-abort":
                CmdManager.StartRecvAbortEvent(peer, xmlRequest);
                break;

            default:
                CmdManager.StartUnknownEvent(peer, xmlRequest);
                break;
            }
        }