private void OnGbxCallback(GbxCallbackEventArgs e) { if (EventGbxCallback != null) { EventGbxCallback(this, e); } }
private void OnDataArrive(IAsyncResult iar) { // end receiving and check if connection's still alive ... try { tcpSocket.EndReceive(iar); // receive the message from the server ... GbxCall call = XmlRpc.ReceiveCall(this.tcpSocket, m_buffer); // watch out for the next calls ... m_buffer = new byte[8]; asyncResult = tcpSocket.BeginReceive(m_buffer, 0, m_buffer.Length, SocketFlags.None, new AsyncCallback(OnDataArrive), null); if (call.Type == MessageTypes.Callback) { // throw new event ... GbxCallbackEventArgs eArgs = new GbxCallbackEventArgs(call); OnGbxCallback(eArgs); } else { // add the response to the queue ... lock (this) { responses.Add(call.Handle, call); } // callback if any method was set ... if (callbackList[call.Handle] != null) { ((GbxCallCallbackHandler)callbackList[call.Handle]).BeginInvoke(call, null, null); callbackList.Remove(call.Handle); } } } catch { this.m_connected = false; // something went wrong :S tcpSocket.Close(); // release a disconnect event ... OnDisconnectCallback(); } finally { // we received something :) callRead.Set(); } }
void Client_EventGbxCallback(object o, XmlRpc.GbxCallbackEventArgs e) { lock (m_lockCallback) { ParseEventGbx(e); } return; SimpleDelegate d = delegate() { ParseEventGbx(e); }; ThreadStart threadDelegate = new ThreadStart(d); new System.Threading.Thread(threadDelegate).Start(); }
private void ParseEventGbx(XmlRpc.GbxCallbackEventArgs e) { if (e.Response.MethodName == "ManiaPlanet.PlayerChat" && e.Response.Params.Count == 4) { try { Structs.PlayerChat PC = new Structs.PlayerChat(); PC.PlayerUid = (int)e.Response.Params[0]; PC.Login = (string)e.Response.Params[1]; PC.Text = (string)e.Response.Params[2]; PC.IsRegisteredCmd = (bool)e.Response.Params[3]; if (OnPlayerChat != null) { OnPlayerChat(PC); } } catch { } } else if (e.Response.MethodName == "ManiaPlanet.PlayerConnect" && e.Response.Params.Count == 2) { try { Structs.PlayerConnect PC = new Structs.PlayerConnect(); PC.Login = (string)e.Response.Params[0]; PC.IsSpectator = (bool)e.Response.Params[1]; if (OnPlayerConnect != null) { OnPlayerConnect(PC); } } catch { } } else if (e.Response.MethodName == "ManiaPlanet.PlayerDisconnect" && e.Response.Params.Count == 1) { try { Structs.PlayerDisconnect PD = new Structs.PlayerDisconnect(); PD.Login = (string)e.Response.Params[0]; if (OnPlayerDisconnect != null) { OnPlayerDisconnect(PD); } } catch { } } else if (e.Response.MethodName == "ManiaPlanet.VoteUpdated" && e.Response.Params.Count == 4) { try { Structs.VoteUpdated VU = new Structs.VoteUpdated(); VU.StateName = (string)e.Response.Params[0]; VU.Login = (string)e.Response.Params[1]; VU.CmdName = (string)e.Response.Params[2]; VU.CmdParam = (string)e.Response.Params[3]; if (OnVoteUpdated != null) { OnVoteUpdated(VU); } } catch { } } else if (e.Response.MethodName == "ManiaPlanet.ModeScriptCallback" && e.Response.Params.Count == 2) { try { Structs.ModeScriptCallback MSC = new Structs.ModeScriptCallback(); MSC.Param1 = (string)e.Response.Params[0]; MSC.Param2 = (string)e.Response.Params[1]; if (OnModeScriptCallback != null) { OnModeScriptCallback(MSC); } } catch { } } else { // Unhandled callback } }
private void OnGbxCallback(GbxCallbackEventArgs e) { if (EventGbxCallback != null) EventGbxCallback(this, e); }
private void OnDataArrive(IAsyncResult iar) { // end receiving and check if connection's still alive ... try { tcpSocket.EndReceive(iar); // receive the message from the server ... GbxCall call = XmlRpc.ReceiveCall(this.tcpSocket, m_buffer); // watch out for the next calls ... m_buffer = new byte[8]; asyncResult = tcpSocket.BeginReceive(m_buffer, 0, m_buffer.Length, SocketFlags.None, new AsyncCallback(OnDataArrive), null); if (call.Type == MessageTypes.Callback) { // throw new event ... GbxCallbackEventArgs eArgs = new GbxCallbackEventArgs(call); OnGbxCallback(eArgs); } else { // add the response to the queue ... lock (this) { responses.Add(call.Handle, call); } // callback if any method was set ... if (callbackList[call.Handle] != null) { ((GbxCallCallbackHandler)callbackList[call.Handle]).BeginInvoke(call, null, null); callbackList.Remove(call.Handle); } } } catch { this.m_connected = false; // something went wrong :S tcpSocket.Close(); // release a disconnect event ... OnDisconnectCallback(); } finally { // we received something :) callRead.Set(); } }