Beispiel #1
0
        //public static string GetRandomInsult()
        //{
        //    string fileName = Settings.InsultListFileName;
        //    string[] list = System.IO.File.ReadAllLines(fileName);

        //    Random rnd = new Random(DateTime.UtcNow.Millisecond);
        //    int random = rnd.Next(list.Length - 1);

        //    return list[random];
        //}

        internal void ProcessMsg(RSProtoBuffSSHMsg msg)
        {
            byte   extension = RSProtoBuf.GetRpcMsgIdExtension(msg.MsgID);
            ushort service   = RSProtoBuf.GetRpcMsgIdService(msg.MsgID);

            System.Diagnostics.Debug.WriteLineIf(DEBUG, "Processing Msg " + msg.ReqID + " .....");
            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ext: " + extension + " - service: " + service + " - submsg: " + RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID));
            //System.Diagnostics.Debug.WriteLineIf(true, "Processing Msg " + msg.ReqID + " .....");
            //System.Diagnostics.Debug.WriteLineIf(true, "ext: " + extension + " - service: " + service + " - submsg: " + RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID));
            //_gui.tb_out.AppendText(" -> " + msg.ReqID + "\n");
            switch (extension)
            {
            case (byte)rsctrl.core.ExtensionId.CORE:
                switch (service)
                {
                case (ushort)PackageId.CHAT:
                    ProcessChat(msg);
                    break;

                case (ushort)PackageId.FILES:
                    ProcessFiles(msg);
                    break;

                case (ushort)PackageId.PEERS:
                    ProcessPeer(msg);
                    break;

                case (ushort)PackageId.SEARCH:
                    ProcessSearch(msg);
                    break;

                case (ushort)PackageId.SYSTEM:
                    ProcessSystem(msg);
                    break;

                default:
                    System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessMsg: unknown service " + service);
                    break;
                }     // service
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessMsg: unknown extension " + extension);
                break;
            } // extension
            System.Diagnostics.Debug.WriteLineIf(DEBUG, "##########################################");
        }
Beispiel #2
0
        static private void ProcessMsgFromThread(RSProtoBuffSSHMsg msg)
        {
            System.Console.WriteLine("got msg");

            /*
             * So we received a RPC message. What do we know at this point?
             * We know that the magic code of the message is ok which means that the chance is high that the rest is ok, too.
             *
             *
             * First of all we should check if the message is a response.
             * Since the server only sends responses we do not expect anything else.
             *
             * Note: actually the lib is doing this on its own and you can skip this test.
             * (I keep it for educational purpose :P)
             */
            if (!RSProtoBuf.IsRpcMsgIdResponse(msg.MsgID))
            {
                return;
            }

            /*
             * Next step is to get the informations about the message:
             *      extension, service and submsg
             *
             * These 3 things define the content of the message.
             * (In this example i only requested the system status so i only expect a response to this call)
             */
            byte   extension = RSProtoBuf.GetRpcMsgIdExtension(msg.MsgID);
            ushort service   = RSProtoBuf.GetRpcMsgIdService(msg.MsgID);
            byte   submsg    = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            // check extension
            if (extension != (byte)rsctrl.core.ExtensionId.CORE)
            {
                return;
            }

            // check service
            if (service != (ushort)rsctrl.core.PackageId.SYSTEM)
            {
                return;
            }

            // check submsg
            if (submsg != (byte)rsctrl.system.ResponseMsgIds.MsgId_ResponseSystemStatus)
            {
                return;
            }

            /*
             * Now we know the content of the message and can deserialize it
             * (The example message is a response to our system status request!)
             */

            rsctrl.system.ResponseSystemStatus response = new rsctrl.system.ResponseSystemStatus();
            Exception e;

            if (!RSProtoBuf.Deserialize <rsctrl.system.ResponseSystemStatus>(msg.ProtoBuffMsg, out response, out e))
            {
                System.Console.WriteLine("ProcessSystemstatus: error deserializing " + e.Message);
            }

            /*
             * Last thing you should do is to check if the response.status is SUCCESS.
             * In any other case something went wrong.
             *
             * After this you can continue processing the message in the proper way e.g. update system status
             */
            if (response.status == null || response.status.code != rsctrl.core.Status.StatusCode.SUCCESS)
            {
                return;
            }

            System.Console.WriteLine("Systemstatus: ");
            System.Console.WriteLine(" -- peers: " + response.no_peers);
            System.Console.WriteLine(" -- online: " + response.no_connected);
        }