private async Task OnCommandReceived(string line) { try { dynamic obj = serializer.DeserializeLine(line); Trace.TraceInformation("Chobbyla << {0}", line); await Process(obj); } catch (Exception ex) { Trace.TraceError("{0} error processing line {1} : {2}", this, line, ex); } }
private void TimerOnElapsed(object sender) { try { if (isDisposed) { return; } timer?.Stop(); if (tickCounter % 50 == 0) { if (!IsOnline) { if (SteamAPI.Init() && SteamAPI.IsSteamRunning()) { IsOnline = true; OnSteamOnline(); } } } if (IsOnline) { if (SteamAPI.IsSteamRunning()) { SteamAPI.RunCallbacks(); uint networkSize; while (SteamNetworking.IsP2PPacketAvailable(out networkSize)) { try { var buf = new byte[networkSize]; CSteamID remoteUser; if (SteamNetworking.ReadP2PPacket(buf, networkSize, out networkSize, out remoteUser)) { var str = Encoding.UTF8.GetString(buf); Trace.TraceInformation("SteamP2P << {0} : {1}", remoteUser.m_SteamID, str); dynamic cmd = steamCommandSerializer.DeserializeLine(str); ProcessMessage(remoteUser.m_SteamID, cmd); } } catch (Exception ex) { Trace.TraceError("Error processing steam P2P message: {0}", ex); } } } else { IsOnline = false; SteamOffline(); } } } catch (DllNotFoundException ex) { Trace.TraceWarning("Error initializing steam, disabling susbystem: {0} library not found", ex.Message); if (timer != null) { timer.Dispose(); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } finally { tickCounter++; if (!isDisposed) { timer?.Start(); } } }