SendMyPresence() public method

Sends our Presence, the packet is built of Status, Show and Priority
public SendMyPresence ( ) : void
return void
Ejemplo n.º 1
0
        static void Main(string[] args) {
            Console.Title = "XMPPduino";

            xmppCon = new XmppClientConnection();

            System.ComponentModel.IContainer components = new System.ComponentModel.Container();
            serialPort = new System.IO.Ports.SerialPort(components);

            serialPort.PortName = Config.COM_PORT;
            serialPort.BaudRate = Config.Baud_Rate;

            xmppCon = new XmppClientConnection();
            xmppCon.Username = Config.Username;
            xmppCon.Password = Config.Password;
            xmppCon.SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct;
            xmppCon.ConnectServer = "talk.google.com";
            xmppCon.Port = 5222;
            xmppCon.UseStartTLS = true;
            xmppCon.AutoResolveConnectServer = false;
            xmppCon.Show = ShowType.chat;
            xmppCon.Server = Config.Server;

            xmppCon.AutoAgents = false;
            xmppCon.AutoPresence = true;
            xmppCon.AutoRoster = true;

            try {
                xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
                xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
                xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
                xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
                xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
                xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
                xmppCon.Open();
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Wait("Login to server, please wait");
            bool bQuit = false;

            while (!bQuit) {
                string command = Console.ReadLine();
                string[] commands = command.Split(' ');

                switch (commands[0].ToLower()) {
                    case "quit":
                        bQuit = true;
                        break;
                    case "msg":
                        string msg = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Send(new Message(new Jid(commands[1]), MessageType.chat, msg));
                        break;
                    case "status":
                        switch (commands[1]) {
                            case "online":
                                xmppCon.Show = ShowType.NONE;
                                break;
                            case "away":
                                xmppCon.Show = ShowType.away;
                                break;
                            case "xa":
                                xmppCon.Show = ShowType.xa;
                                break;
                            case "chat":
                                xmppCon.Show = ShowType.chat;
                                break;
                        }
                        string status = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Status = status;
                        xmppCon.SendMyPresence();
                        break;
                }
            }
            xmppCon.Close();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            XmppClientConnection xmppCon = new XmppClientConnection();

            Console.Title = "Console Client";

            // read the jid from the console
            PrintHelp("Enter you Jid ([email protected]): ");
            Jid jid = new Jid(Console.ReadLine());

            PrintHelp(String.Format("Enter password for '{0}': ", jid.ToString()));

            xmppCon.Password = Console.ReadLine();
            xmppCon.Username = jid.User;
            xmppCon.Server = jid.Server;
            xmppCon.AutoAgents = false;
            xmppCon.AutoPresence = true;
            xmppCon.AutoRoster = true;
            xmppCon.AutoResolveConnectServer = true;

            // Connect to the server now
            // !!! this is asynchronous !!!
            try
            {
                xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
                xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
                xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
                xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
                xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
                xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);

                xmppCon.Open();

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Wait("Login to server, please wait");

            PrintCommands();

            bool bQuit = false;

            while (!bQuit)
            {
                string command = Console.ReadLine();
                string[] commands = command.Split(' ');

                switch (commands[0].ToLower())
                {
                    case "help":
                        PrintCommands();
                        break;
                    case "quit":
                        bQuit = true;
                        break;
                    case "msg":
                        string msg = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Send(new Message(new Jid(commands[1]), MessageType.chat, msg));
                        break;
                    case "status":
                        switch (commands[1])
                        {
                            case "online":
                                xmppCon.Show = ShowType.NONE;
                                break;
                            case "away":
                                xmppCon.Show = ShowType.away;
                                break;
                            case "xa":
                                xmppCon.Show = ShowType.xa;
                                break;
                            case "chat":
                                xmppCon.Show = ShowType.chat;
                                break;
                        }
                        string status = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Status = status;
                        xmppCon.SendMyPresence();
                        break;
                }
            }

            // close connection
            xmppCon.Close();
        }
Ejemplo n.º 3
0
        //消息处理
        void objXmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            string strMsg = null;

            //G_Status("ReciveMsg", "【接收消息】 From:" + msg.From.Bare + " Msg:" + msg.Body);

            if (SystemCommand(msg.Body))
            {
                string[] arrCmd = msg.Body.Split(' ');
                if (arrCmd[0].ToLower() == "status")
                {
                    switch (arrCmd[1].ToLower())
                    {
                    case "online":
                        objXmpp.Show = ShowType.NONE;
                        objXmpp.SendMyPresence();
                        G_Status("", "【状态改变】在线");
                        strMsg = "【状态改变】在线";
                        break;

                    case "away":
                        objXmpp.Show = ShowType.away;
                        objXmpp.SendMyPresence();
                        G_Status("", "【状态改变】闲置");
                        strMsg = "【状态改变】闲置";
                        break;

                    case "busy":
                        objXmpp.Show = ShowType.dnd;
                        objXmpp.SendMyPresence();
                        G_Status("", "【状态改变】忙碌");
                        strMsg = "【状态改变】忙碌";
                        break;

                    case "cpu":
                        strMsg = SIC._CPU;
                        break;

                    case "disk":
                        strMsg = SIC.DiskInfo();
                        break;

                    case "file":
                        FileTransfer FT = new FileTransfer(objXmpp, new Jid("*****@*****.**"));
                        break;
                    }
                }
                //agsXMPP.Jid jid = new agsXMPP.Jid(msg.From.Bare);
                //Message autoReply = new Message(jid, MessageType.chat, strMsg);
                //objXmpp.Send(autoReply);
                //G_Status("SendMsg", "【发送消息】 To:" + msg.From.Bare + " Msg:" + autoReply.Body);
            }
            else
            {
                //strMsg = msg.Body;
                //agsXMPP.Jid jid = new agsXMPP.Jid(msg.From.Bare);
                //Message autoReply = new Message(jid, MessageType.chat, strMsg);
                //objXmpp.Send(autoReply);
                //G_Status("SendMsg", "【发送消息】 To:" + msg.From.Bare + " Msg:" + autoReply.Body);
            }
        }