static void CallbackSink_OnHostToClient (CommsInfo info) { switch (info.Type) { case "txt": messageReceived = info.Message; receivedMsg.Set (); break; case "connect": Console.WriteLine (info.Code + "-" + info.Message); break; case "disconnect": Console.WriteLine (info.Code + "-" + info.Message); break; } }
/// <summary> /// Proxy / Receive a message from the server and send it to our callback /// </summary> /// <param name="info"></param> void CallbackSink_OnHostToClient(CommsInfo info) { // EXAMPLE (Each game is Different, check your Assembly-CSharp.dll) gameConfiguration = info.GConfig; StringBuilder sb = new StringBuilder(); sb.AppendLine("RailsCost=" + gameConfiguration.RailsCost.ToString()); sb.AppendLine("RailsRefund=" + gameConfiguration.RailsRefund.ToString()); sb.AppendLine("NumBaseCars=" + gameConfiguration.EngineMaxVagonsBase.ToString()); sb.AppendLine("NumCarsPerGen=" + gameConfiguration.EngineMaxVagonsPerGeneration.ToString()); sb.AppendLine("EnginePrice=" + gameConfiguration.EnginePriceBase.ToString()); sb.AppendLine("EnginePricePerGen=" + gameConfiguration.EnginePricePerGeneration.ToString()); sb.AppendLine("EnginePriceUpgrade=" + gameConfiguration.EnginePricePerUpgrade.ToString()); sb.AppendLine("EngineFullLoadSpeed=" + gameConfiguration.EngineSpeedFullLoad.ToString()); sb.AppendLine("EngineFullLoadAccel=" + gameConfiguration.EngineAccelerationFullLoad.ToString()); txtToServer.Text = sb.ToString(); if (this.txtFromServer.InvokeRequired) { this.txtFromServer.Invoke(new delegateCommsInfo(CallbackSink_OnHostToClient), new object[] { info }); } else { if (info.Message != "NOTLOADED") { this.txtFromServer.Text = "[Received Message]: " + info.Message + "\r\n " + sb.ToString().Replace("\r\n", "\r\n ") + "\r\n" + this.txtFromServer.Text; } else { txtToServer.Text = sb.ToString(); this.txtFromServer.Text = "Load a Level Before Sending!"; } } //---------------------------------------------------------------------------------------------------------------------------------- }
public void SendMessageToServer (CommsInfo Message) { _ClientToServer.Enqueue (Message); }
public void HandleToClient (CommsInfo info) { if (OnHostToClient != null) OnHostToClient (info); }
static void ClientToHost (CommsInfo info) { switch (info.Type) { case "txt": receivedMsg = info.Message; break; } }