Ejemplo n.º 1
0
 protected HubMessage ParseMessage(string raw)
 {
     raw = raw.Replace(this.Seperator, "");
     HubMessage msg = new HubMessage(hub, raw);
     if (!string.IsNullOrEmpty(raw))
     {
         switch (raw[0])
         {
             case '$':
                 int pos;
                 string cmd = null;
                 if ((pos = raw.IndexOf(' ')) != -1)
                     cmd = raw.Substring(0, pos).ToLower();
                 else
                 {
                     if (raw.Length >= 10)
                         break;
                     cmd = raw.ToLower();
                 }
                 if (cmd == null || cmd.Equals(string.Empty))
                     break;
                 switch (cmd)
                 {
                     case "$lock":
                         msg = new Lock(hub, raw); break;
                     case "$supports":
                         msg = new Supports(hub, raw); break;
                     case "$hubname":
                         msg = new HubNmdc.HubName(hub, raw); break;
                     case "$hello":
                         msg = new Hello(hub, raw); break;
                     case "$myinfo":
                         msg = new MyINFO(hub, raw); break;
                     case "$nicklist":
                         msg = new NickList(hub, raw); break;
                     case "$oplist":
                         msg = new OpList(hub, raw); break;
                     case "$to:":
                         msg = new To(hub, raw); break;
                     case "$quit":
                         msg = new Quit(hub, raw); break;
                     case "$getpass":
                         msg = new GetPass(hub, raw); break;
                     case "$logedin":
                         msg = new LogedIn(hub, raw); break;
                     case "$validatedenide":
                         msg = new ValidateDenide(hub, raw); break;
                     case "$forcemove":
                         msg = new ForceMove(hub, raw); break;
                     case "$connecttome":
                         msg = new ConnectToMe(hub, raw); break;
                     case "$revconnecttome":
                         msg = new RevConnectToMe(hub, raw); break;
                     case "$search":
                         msg = new Search(hub, raw); break;
                     case "$sr":
                         msg = new SR(hub, raw); break;
                 }
                 break;
             default:
                 // No command. Assume MainChat.
                 msg = new MainChat(hub, raw);
                 break;
         }
     }
     return msg;
 }
Ejemplo n.º 2
0
        public void ActOnOutMessage(FmdcEventArgs e)
        {
            if (e.Action.Equals(Actions.MainMessage))
            {
                Containers.MainMessage main = (Containers.MainMessage)e.Data;
                hub.Send(new MainChat(hub, hub.Me.ID, main.Content));
            }
            else if (e.Action.Equals(Actions.PrivateMessage))
            {
                Containers.PrivateMessage pm = (Containers.PrivateMessage)e.Data;
                To to = null;
                hub.Send(to = new To(hub, pm.To, pm.Content));
                this.ParseRaw(to.Raw);
            }
            else if (e.Action.Equals(Actions.Password))
            {
                hub.Send(new MyPass(hub, e.Data.ToString()));
            }
            else if (e.Action.Equals(Actions.Search))
            {
                hub.Send(new Search(hub, (SearchInfo)e.Data));
            }
            else if (e.Action.Equals(Actions.StartTransfer))
            {
                UserInfo usrInfo;
                User usr = e.Data as User;
                if (usr == null)
                {
                    usrInfo = e.Data as UserInfo;
                    if (usrInfo == null)
                    {
                        return;
                    }
                }
                else
                {
                    usrInfo = usr.UserInfo;
                }

                switch (hub.Me.Mode)
                {
                    case ConnectionTypes.Direct:
                    case ConnectionTypes.UPnP:
                    case ConnectionTypes.Forward:
                        Update(hub, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(usrInfo.ID, hub, usrInfo)));
            #if !COMPACT_FRAMEWORK
            // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it.
                        if (
                            usrInfo.ContainsKey(UserInfo.SECURE) &&
                            hub.Me.ContainsKey(UserInfo.SECURE) &&
                            !string.IsNullOrEmpty( hub.Me.Get(UserInfo.SECURE) )
                            )
                            hub.Send(new ConnectToMe(usrInfo.ID, hub.Share.Port, hub, SecureProtocols.TLS));
                        else
            #endif
                            hub.Send(new ConnectToMe(usrInfo.ID, hub.Share.Port, hub));
                        break;
                    case ConnectionTypes.Passive:
                    case ConnectionTypes.Socket5:
                    case ConnectionTypes.Unknown:
                    default:
                        if (usrInfo.Mode == ConnectionTypes.Passive)
                        {
                            break;
                        }
                        hub.Send(new RevConnectToMe(usrInfo.ID, hub));
                        break;
                }
            }
        }