// ---------- 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; } }
// ---------- 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; } }
// ---------- 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; } }
// ---------- 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; } }
// ---------- 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; } }
// ---------- 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; } }
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); }
//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, "##########################################"); }