Beispiel #1
0
        private void ProcessChatMsg(RSProtoBuffSSHMsg msg)
        {
            EventChatMessage response = new EventChatMessage();
            Exception        e;

            if (RSProtoBuf.Deserialize <EventChatMessage>(msg.ProtoBuffMsg, out response, out e))
            {
                switch (response.msg.id.chat_type)
                {
                case ChatType.TYPE_GROUP:
                    //_b.ChatProcessor.AddMsgToGroupChat(response);
                    _b.ChatProcessor.AddMsgToLobby(ChatProcessor.BROADCAST, response.msg);
                    break;

                case ChatType.TYPE_LOBBY:
                    _b.ChatProcessor.AddMsgToLobby(response.msg.id.chat_id, response.msg);
                    break;

                case ChatType.TYPE_PRIVATE:
                    break;

                default:
                    System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessChatMsg: unknown chat type");
                    break;
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessChatMsg: error deserializing " + e.Message);
            }
        }
Beispiel #2
0
        private void ProcessSystemStatus(RSProtoBuffSSHMsg msg)
        {
            ResponseSystemStatus response = new ResponseSystemStatus();
            Exception            e;

            if (RSProtoBuf.Deserialize <ResponseSystemStatus>(msg.ProtoBuffMsg, out response, out e))
            {
                _b.GUI.UpdateSystemStatus(response);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessSystemstatus: error deserializing " + e.Message);
            }
        }
Beispiel #3
0
        private void ProcessControllDownload(RSProtoBuffSSHMsg msg)
        {
            ResponseControlDownload response = new ResponseControlDownload();
            Exception e;

            if (RSProtoBuf.Deserialize <ResponseControlDownload>(msg.ProtoBuffMsg, out response, out e))
            {
                _b.GUI.tb_out.AppendText("ReqContrDL response:" + response.status.code + "\n");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessControllDownload: error deserializing " + e.Message);
            }
        }
Beispiel #4
0
        private void ProcessSystemAccount(RSProtoBuffSSHMsg msg)
        {
            ResponseSystemAccount response = new ResponseSystemAccount();
            Exception             e;

            if (RSProtoBuf.Deserialize <ResponseSystemAccount>(msg.ProtoBuffMsg, out response, out e))
            {
                _b.PeerProcessor.SetOwnID(response);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessSystemstatus: error deserializing " + e.Message);
            }
        }
Beispiel #5
0
        private void ProcessSendMsg(RSProtoBuffSSHMsg msg)
        {
            ResponseSendMessage response = new ResponseSendMessage();
            Exception           e;

            if (RSProtoBuf.Deserialize <ResponseSendMessage>(msg.ProtoBuffMsg, out response, out e))
            {
                _b.GUI.tb_out.AppendText("ReqSendMsg response:" + response.status.code + "\n");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessChatMsg: error deserializing " + e.Message);
            }
        }
Beispiel #6
0
        private void ProcessLobbyInvite(RSProtoBuffSSHMsg msg)
        {
            EventLobbyInvite response = new EventLobbyInvite();
            Exception        e;

            if (RSProtoBuf.Deserialize <EventLobbyInvite>(msg.ProtoBuffMsg, out response, out e))
            {
                _b.ChatProcessor.LobbyInvite(response);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessChatMsg: error deserializing " + e.Message);
            }
        }
Beispiel #7
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 #8
0
        private void ProcessShareDirList(RSProtoBuffSSHMsg msg)
        {
            ResponseShareDirList response = new ResponseShareDirList();
            Exception            e;

            if (RSProtoBuf.Deserialize <ResponseShareDirList>(msg.ProtoBuffMsg, out response, out e))
            {
                if (response.status.code == Status.StatusCode.SUCCESS)
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessShareDirList: error deserializing " + e.Message);
            }
        }
Beispiel #9
0
        private void ProcessChatLobbies(RSProtoBuffSSHMsg msg)
        {
            ResponseChatLobbies response = new ResponseChatLobbies();
            Exception           e;

            if (RSProtoBuf.Deserialize <ResponseChatLobbies>(msg.ProtoBuffMsg, out response, out e))
            {
                if (response.status.code == Status.StatusCode.SUCCESS)
                {
                    _b.ChatProcessor.UpdateChatLobbies(response);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessChatMsg: error deserializing " + e.Message);
            }
        }
Beispiel #10
0
        //private void ProcessAddPeer(RSProtoBuffSSHMsg msg)
        //{
        //    Respon response = new ResponseAddPeer();
        //    Exception e;
        //    if (RSProtoBuf.Deserialize<ResponseAddPeer>(msg.ProtoBuffMsg, out response, out e))
        //        _b.GUI.tb_out.AppendText("AddPeer response: " + response.status.code + "\n");
        //    else
        //        System.Diagnostics.Debug.WriteLine("ProcessAddPeer: error deserializing " + e.Message);
        //}

        //private void ProcessModifyPeer(RSProtoBuffSSHMsg msg)
        //{
        //    ResponseModifyPeer response = new ResponseModifyPeer();
        //    Exception e;
        //    if (RSProtoBuf.Deserialize<ResponseModifyPeer>(msg.ProtoBuffMsg, out response, out e))
        //        _b.GUI.tb_out.AppendText("AddPeer response: " + response.status.code + "\n");
        //    else
        //        System.Diagnostics.Debug.WriteLine("ProcessModifyPeer: error deserializing " + e.Message);
        //}

        private void ProcessPeerList(RSProtoBuffSSHMsg msg)
        {
            ResponsePeerList response = new ResponsePeerList();
            Exception        e;

            if (RSProtoBuf.Deserialize <ResponsePeerList>(msg.ProtoBuffMsg, out response, out e))
            {
                if (response.status.code == Status.StatusCode.SUCCESS)
                {
                    //_b.PeerProcessor.ProcessResponsePeerList(msg.ReqID, response);
                    _b.PeerProcessor.UpdatePeerList(response);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("ProcessPeerList: error deserializing " + e.Message);
                }
            }
        }
Beispiel #11
0
        private void ProcessTransferlist(RSProtoBuffSSHMsg msg)
        {
            ResponseTransferList response = new ResponseTransferList();
            Exception            e;

            if (RSProtoBuf.Deserialize <ResponseTransferList>(msg.ProtoBuffMsg, out response, out e))
            {
                if (response.status.code == Status.StatusCode.SUCCESS)
                {
                    _b.FileProcessor.UpdateFileTransfers(response, msg.ReqID);
                    //_b.FileProcessor.UpdateFileTransfersNEW(response, msg.ReqID);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessTransferlist: error deserializing " + e.Message);
            }
        }
Beispiel #12
0
        // ---------- stream ----------

        private void ProcessStream(RSProtoBuffSSHMsg msg)
        {
            byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            switch (submsg)
            {
            case (byte)rsctrl.stream.ResponseMsgIds.MsgId_ResponseStreamDetail:
                ProcessStreamDetails(msg);
                break;

            case (byte)rsctrl.stream.ResponseMsgIds.MsgId_ResponseStreamData:
                ProcessStreamData(msg);
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessStream: unknown submsg " + submsg);
                break;
            }
        }
Beispiel #13
0
        // ---------- search ----------
        private void ProcessSearch(RSProtoBuffSSHMsg msg)
        {
            byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            switch (submsg)
            {
            case (byte)rsctrl.search.ResponseMsgIds.MsgId_ResponseSearchIds:
                ProcessSearchIDs(msg);
                break;

            case (byte)rsctrl.search.ResponseMsgIds.MsgId_ResponseSearchResults:
                ProcessSearchResults(msg);
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessSearch: unknown submsg " + submsg);
                break;
            }
        }
Beispiel #14
0
        // ---------- system ----------
        private void ProcessSystem(RSProtoBuffSSHMsg msg)
        {
            byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            switch (submsg)
            {
            case (byte)rsctrl.system.ResponseMsgIds.MsgId_ResponseSystemStatus:
                ProcessSystemStatus(msg);
                break;

            case (byte)rsctrl.system.ResponseMsgIds.MsgId_ResponseSystemAccount:
                ProcessSystemAccount(msg);
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessSystem: unknown submsg " + submsg);
                break;
            }
        }
Beispiel #15
0
        private void ProcessStreamData(RSProtoBuffSSHMsg msg)
        {
            ResponseStreamData response = new ResponseStreamData();
            Exception          e;

            if (RSProtoBuf.Deserialize <ResponseStreamData>(msg.ProtoBuffMsg, out response, out e))
            {
                if (response.status.code == Status.StatusCode.SUCCESS)
                {
                    _b.StreamProcessor.StreamData(response);
                }
                else
                {
                    _b.GUI.tb_out.AppendText("StreamData response: " + response.status.code + "\n");
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessStreamData: error deserializing " + e.Message);
            }
        }
Beispiel #16
0
        private void ProcessSearchIDs(RSProtoBuffSSHMsg msg)
        {
            ResponseSearchIds response = new ResponseSearchIds();
            Exception         e;

            if (RSProtoBuf.Deserialize <ResponseSearchIds>(msg.ProtoBuffMsg, out response, out e))
            {
                if (response.status.code == Status.StatusCode.SUCCESS)
                {
                    _b.SearchProcessor.RegisterSearchIDs(msg.ReqID, response);
                }
                else
                {
                    _b.GUI.tb_out.AppendText("SearchIDs response: " + response.status.code + "\n");
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("ProcessSearchIDs: error deserializing " + e.Message);
            }
        }
Beispiel #17
0
        // ---------- peers ----------
        private void ProcessPeer(RSProtoBuffSSHMsg msg)
        {
            byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            switch (submsg)
            {
            //case (byte)rsctrl.peers.ResponseMsgIds.MsgId_RequestAddPeer:
            //    ProcessAddPeer(msg);
            //    break;
            //case (byte)rsctrl.peers.ResponseMsgIds.MsgId_RequestModifyPeer:
            //    ProcessModifyPeer(msg);
            //    break;
            case (byte)rsctrl.peers.ResponseMsgIds.MsgId_ResponsePeerList:
                ProcessPeerList(msg);
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessPeer: unknown submsg " + submsg);
                break;
            }
        }
Beispiel #18
0
        // ---------- files ----------
        private void ProcessFiles(RSProtoBuffSSHMsg msg)
        {
            byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            switch (submsg)
            {
            case (byte)rsctrl.files.ResponseMsgIds.MsgId_ResponseControlDownload:
                ProcessControllDownload(msg);
                break;

            case (byte)rsctrl.files.ResponseMsgIds.MsgId_ResponseTransferList:
                ProcessTransferlist(msg);
                break;

            case (byte)rsctrl.files.ResponseMsgIds.MsgId_ResponseShareDirList:
                ProcessShareDirList(msg);
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessFiles: unknown submsg " + submsg);
                break;
            }
        }
Beispiel #19
0
        // ---------- chat ----------
        private void ProcessChat(RSProtoBuffSSHMsg msg)
        {
            //System.Diagnostics.Debug.WriteLine(" ----------- processing chat ----------");
            byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID);

            switch (submsg)
            {
            case (byte)rsctrl.chat.ResponseMsgIds.MsgId_EventChatMessage:
                ProcessChatMsg(msg);
                break;

            case (byte)rsctrl.chat.ResponseMsgIds.MsgId_EventLobbyInvite:
                ProcessLobbyInvite(msg);
                break;

            case (byte)rsctrl.chat.ResponseMsgIds.MsgId_ResponseChatLobbies:
                ProcessChatLobbies(msg);
                break;

            case (byte)rsctrl.chat.ResponseMsgIds.MsgId_ResponseRegisterEvents:
                ProcessRegisterEvents(msg);
                break;

            case (byte)rsctrl.chat.ResponseMsgIds.MsgId_ResponseSendMessage:
                ProcessSendMsg(msg);
                break;

            case (byte)rsctrl.chat.RequestMsgIds.MsgId_RequestChatHistory:
                // don't need this -> drop it
                break;

            default:
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ProcessChat: unknown submsg " + submsg);
                break;
            }
        }
Beispiel #20
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);
        }