} // ThreadProc public void MsgLoop() { bool bDone = false, bRes = true; RMMsg rmMsg = null; XmlMsg xMsg = null; while (!bDone) { try { rmMsg = (RMMsg)(m_aqMsgIn.Pop()); xMsg = XmlMsg.Parse(rmMsg.m_sMsgDecoded); switch (xMsg.MsgType) { case XmlMsg.eMsgTypes.Ack: case XmlMsg.eMsgTypes.NOP: case XmlMsg.eMsgTypes.Ping: { // All messages we can ignore } break; case XmlMsg.eMsgTypes.SBResetComp: { bRes = ResetSBComponents(xMsg); } break; default: { m_Logger.Log(Level.Warning, string.Format("LRMWorkerThread.MsgLoop: Unsupported msg type: {0}.{1}", xMsg.MsgType.ToString(), xMsg.MsgType)); } break; } xMsg = null; rmMsg = null; } catch (Exception exc) { m_Logger.Log(exc); } } } // MsgLoop
} // NetLoop public bool SendAckReceived(RMMsg i_Msg) { bool bRet = true; Byte[] abMsg = null; int iSeqNum = -1; int iStart = -1, iEnd = -1; int iRes = 0; XmlMsg xMsg = null; try { iStart = i_Msg.m_sMsgDecoded.IndexOf("<" + XmlMsg.eMsgTags.SeqNum.ToString() + ">") + XmlMsg.eMsgTags.SeqNum.ToString().Length + 2; iEnd = i_Msg.m_sMsgDecoded.IndexOf("</" + XmlMsg.eMsgTags.SeqNum.ToString() + ">"); if ((iStart < 0) || (iEnd < 1)) { m_Logger.Log(Level.Exception, "UdpMsgListenerThread.SendAckReceived: SeqNum tags not found."); } else { iSeqNum = int.Parse(i_Msg.m_sMsgDecoded.Substring(iStart, (iEnd - iStart))); xMsg = new XmlMsg(); xMsg.MsgType = XmlMsg.eMsgTypes.Ack; xMsg.SeqNum = iSeqNum; abMsg = Encoding.ASCII.GetBytes(xMsg.ToString()); // FIX - Should this be UTF8? iRes = m_receivingUdpClient.Send(abMsg, abMsg.Length, i_Msg.m_EP); } } catch (Exception exc) { bRet = false; m_Logger.Log(exc); } return(bRet); } // SendAckReceived
static void Main(string[] args) { //TODO:Refactor a lot.. //TODO:Sepratede the logic from the gui.. string hostServer = ""; int hostServerPort = 3; List <string> listOfUser = new List <string>(); string pickUserToSendToo; XmlMsg xmlPareser; Message msgs; Thread xmlThread; ClientToServerController clientController; Console.WriteLine("Server to connect to\n1.Camillas Server\n2.ImortalServer(Made by Tobias & Wolter)"); ConsoleKeyInfo serverChose = Console.ReadKey(); //User picks what server to connect switch (serverChose.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: hostServer = "172.16.2.30"; hostServerPort = 8888; break; case ConsoleKey.D2: case ConsoleKey.NumPad2: hostServer = "172.16.2.30"; hostServerPort = 50001; break; } Console.Clear(); Console.Write("1.SimpleString\n2.Xml\n3.Aes\n4.RSA and Aes."); ConsoleKeyInfo key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: clientController = new ClientToServerController(new ComFactory().CreateComHandler(hostServer, hostServerPort)); Thread thread = new Thread(clientController.ComHandler.startClient); thread.Start(); string ServerMessagse = "bla"; while (key.Key != ConsoleKey.Q) { Console.Clear(); ServerMessagse = clientController.ComHandler.gettingMsg; if (ServerMessagse == null) { ServerMessagse = "bla bla"; } if (ServerMessagse.Contains("USER-ONLINE")) { listOfUser = ServerMessagse.Replace("\r\n", "").Replace("USER-ONLINE:", "").Split(":").ToList(); for (int i = 0; i < listOfUser.Count; i++) { Console.WriteLine($"{listOfUser[i]}"); } Console.WriteLine("What user do you want to send too? : "); ConsoleKeyInfo userInt = Console.ReadKey(); Console.Clear(); //Console.WriteLine("PickUser" + listOfUser[Convert.ToInt32(Console.ReadLine()) - 1]); //pickUserToSendToo = $"UnkownUser:{listOfUser[Convert.ToInt32(userInt.KeyChar)]}"; } else if (ServerMessagse.Contains("172.16.2.36")) { Console.WriteLine($"Messagse : {clientController.ComHandler.gettingMsg.Split(":")[4]}"); } Console.WriteLine($"msg reviced{clientController.ComHandler.gettingMsg}"); Console.WriteLine("Write msg to send."); string userMsg = $"Duckson:172.16.2.36:Camilla:172.16.2.30:{Console.ReadLine()}"; clientController.ComHandler.SendMsg((hostServerPort == 50001) ? userMsg += "\r\n" : userMsg = $"Duckson:{userMsg}{{END}}"); Console.WriteLine("Press Q to stop \"Chatting\" else press any key.. "); key = Console.ReadKey(); Console.Clear(); } break; case ConsoleKey.D2: case ConsoleKey.NumPad2: xmlPareser = new XmlMsg(); msgs = new Message(); hostServerPort++; clientController = new ClientToServerController(new ComFactory().CreateComHandler(hostServer, hostServerPort)); xmlThread = new Thread(clientController.ComHandler.startClient); xmlThread.Start(); while (key.Key != ConsoleKey.Q) { Console.WriteLine(clientController.ComHandler.gettingMsg); Console.WriteLine("User to send too."); msgs.From = new UserInfomation { Name = "Duckson", Ip = "172.16.2.37" }; msgs.To = new UserInfomation { Name = "UnkownUser", Ip = Console.ReadLine() }; Console.Write("Messagse to send : "); msgs.Mb = new MessagseBody { Body = Console.ReadLine() }; if (hostServerPort == 50002) { SocketMessage message = new SocketMessage("Andi", "AndisPC", "172.16.2.37", "Ligon2", "172.16.2.51", "hej hej"); clientController.ComHandler.SendMsg(message); } else { clientController.ComHandler.SendMsg(msgs); } Console.WriteLine("Press Q to stop \"Chatting\" else press any key.. "); key = Console.ReadKey(); Console.Clear(); } break; case ConsoleKey.D3: case ConsoleKey.NumPad3: //TODO: Finsihe this with aes. // This is sadly not done yet.. xmlPareser = new XmlMsg(); msgs = new Message(); hostServerPort++; clientController = new ClientToServerController(new ComFactory().CreateComHandler(hostServer, hostServerPort)); xmlThread = new Thread(clientController.ComHandler.startClient); xmlThread.Start(); string ivkeys = "W+jcxfBJm37AAZujiktg4qCdy3k8D+vIrj4exFxFpIY=="; RSAEncryptionController aes = new RSAEncryptionController(new RSAEncrpytion(false)); while (key.Key != ConsoleKey.Q) { string messagse = xmlPareser.FormatFromXmlToMessgase(Encoding.UTF8.GetBytes(clientController.ComHandler.gettingMsg)).Mb.Body; aes.DecryptDataWithAES(Encoding.UTF8.GetBytes(messagse)); Console.WriteLine(aes.DecryptDataWithAES(Convert.FromBase64String(messagse))); Console.WriteLine("User to send too."); msgs.From = new UserInfomation { Name = "Duckson", Ip = "172.16.2.37" }; msgs.To = new UserInfomation { Name = "UnkownUser", Ip = Console.ReadLine() }; Console.Write("Messagse to send : "); msgs.Mb = new MessagseBody { Body = Console.ReadLine() }; if (hostServerPort == 50003) { SocketMessage message = new SocketMessage("Andi", "AndisPC", "172.16.2.37", "Ligon2", "172.16.2.51", "hej hej"); clientController.ComHandler.SendMsg(message); } else { clientController.ComHandler.SendMsg(msgs); } Console.WriteLine("Press Q to stop \"Chatting\" else press any key.. "); key = Console.ReadKey(); Console.Clear(); } break; case ConsoleKey.D4: case ConsoleKey.NumPad4: break; } }
} // StartSBProc /// <summary> /// Note: The behavior of the code below is really only appropriate for AudioRtr, /// since it kills off all of the specified components, then restarts them, which /// is not appropriate for AudioMgr & DialogMgr. /// </summary> /// <param name="i_XmlMsg"></param> /// <returns></returns> public bool ResetSBComponents(XmlMsg i_XmlMsg) { #if (false) bool bRet = true, bRes = true; int iRes = -1; string sComp = "", sName = "", sFile = "", sArgs = ""; int ii = 0, iNumComps = 0; StringCollection asNames = null, asFiles = null, asArgs = null; bool bFound = false; try { sComp = i_XmlMsg.Data; m_Logger.Log(Level.Info, "LRMWorkerThread.ResetSBComponents: Restarting '" + sComp + "'."); asNames = new StringCollection(); asFiles = new StringCollection(); asArgs = new StringCollection(); // Kill off components do { iRes = FindComponentInProcessList(sComp, out sFile, out sArgs); if (iRes == -1) { } else { bFound = true; sName = m_aProcs[iRes].Name; if (m_aProcs[iRes].Running) { m_aProcs[iRes].Proc.EnableRaisingEvents = false; m_aProcs[iRes].Proc.Exited -= new EventHandler(proc_Exited); m_aProcs[iRes].Proc.Kill(); } m_aProcs.RemoveAt(iRes); // Add to list to restart (even if it didn't start before.) asNames.Add(sName); asFiles.Add(sFile); asArgs.Add(sArgs); iNumComps++; } }while(iRes != -1); if (!bFound) { m_Logger.Log(Level.Warning, "LRMWorkerThread.ResetSBComponents: Couldn't find '" + sComp + "' in the list."); } // Restart components for (ii = 0; ii < iNumComps; ii++) { bRes = StartSBProc(asNames[ii], asFiles[ii], asArgs[ii]); } } catch (Exception exc) { bRet = false; m_Logger.Log(exc); } #else bool bRet = true; char cSlash = '/'; string sBinPath = "", sCmd = "", sArgs = ""; System.Diagnostics.Process procCmd; try { // Disable raising 'exited' event foreach (SBProcess procChild in m_aProcs) { procChild.Proc.EnableRaisingEvents = false; } // Format command and args if (RunningSystem.RunningPlatform == CLRPlatform.Mono) { cSlash = '/'; } else { //cSlash = '\\'; // We can use '/' on Windows too. cSlash = '/'; } sBinPath = ConfigurationManager.AppSettings["DefaultBinPath"]; if (!(sBinPath.EndsWith("/")) && !(sBinPath.EndsWith("\\"))) { sBinPath += cSlash; } sCmd = sBinPath + "speechbridged"; sArgs = "restart"; procCmd = new Process(); procCmd.StartInfo.FileName = sCmd; procCmd.StartInfo.Arguments = sArgs; m_Logger.Log(Level.Debug, "LRMWorkerThread.ResetSBComponents: Starting '" + sCmd + "', '" + sArgs + "'."); // Run the 'reset' command bRet = procCmd.Start(); Environment.Exit(0); } catch (Exception exc) { bRet = false; m_Logger.Log(Level.Exception, "LRMWorkerThread.ResetSBComponents caught exception: " + exc.ToString()); } #endif return(bRet); } // ResetSBComponents