/// <summary> /// Setup DOTA 2 game coordinator callbacks /// </summary> /// <param name="cb">Manager</param> private void SetupDotaGcCallbacks(CallbackManager cb) { cb.Add <DotaGCHandler.GCWelcomeCallback>(a => { log.Debug("GC session welcomed"); _state.Fire(Trigger.DotaConnected); }); cb.Add <DotaGCHandler.ConnectionStatus>(a => { log.DebugFormat("GC connection status: {0}", a.result.status.ToString("G")); _state.Fire(a.result.status == GCConnectionStatus.GCConnectionStatus_HAVE_SESSION ? Trigger.DotaConnected : Trigger.DotaDisconnected); }); cb.Add <DotaGCHandler.Popup>(a => log.DebugFormat("GC popup message: {0}", a.result.id.ToString("G"))); cb.Add <DotaGCHandler.PracticeLobbySnapshot>(a => HandleLobbyUpdate(a.lobby)); cb.Add <DotaGCHandler.PracticeLobbyLeave>(a => HandleLobbyUpdate(null)); cb.Add <DotaGCHandler.JoinChatChannelResponse>(a => { if (DotaGcHandler.Lobby != null && a.result.channel_id != 0 && a.result.channel_name == "Lobby_" + DotaGcHandler.Lobby.lobby_id) { _lobbyChannelId = a.result.channel_id; JoinedLobbyChat?.Invoke(this, EventArgs.Empty); } }); cb.Add <DotaGCHandler.ChatMessage>( a => { log.DebugFormat("[Chat][" + (a.result.channel_id == _lobbyChannelId ? "Lobby" : a.result.channel_id + "") + "] " + a.result.persona_name + ": " + a.result.text); if (a.result.channel_id != _lobbyChannelId) { return; } }); cb.Add <DotaGCHandler.MatchResultResponse>(c => { Action <CMsgDOTAMatch> cbx; ulong id; id = c.result.match?.match_id ?? _matchId; if (!_callbacks.TryGetValue(id, out cbx)) { return; } _callbacks.Remove(id); log.Warn("Match result response for " + id + ": " + ((EResult)c.result.result).ToString("G")); cbx(c.result.match); }); cb.Add <DotaGCHandler.LobbyInviteSnapshot>(c => { LobbyInviteReceived?.Invoke(this, c.invite); }); cb.Add <DotaGCHandler.PartyInviteSnapshot>(c => { PartyInviteReceived?.Invoke(this, c.invite); }); }
/// <summary> /// Setup steam client callbacks /// </summary> /// <param name="cb"></param> private void SetupSteamCallbacks(CallbackManager cb) { // Handle general connection stuff cb.Add <SteamUser.AccountInfoCallback>(a => { log.DebugFormat("Current name is: {0}, flags {1}, ", a.PersonaName, a.AccountFlags.ToString("G")); UpdatePersona(); }); cb.Add <SteamClient.ConnectedCallback>(a => SteamUser?.LogOn(_logonDetails)); cb.Add <SteamClient.DisconnectedCallback>(a => _state?.Fire(Trigger.SteamDisconnected)); cb.Add <SteamUser.LoggedOnCallback>(a => { log.DebugFormat("Steam signin result: {0}", a.Result.ToString("G")); switch (a.Result) { case EResult.OK: _state?.Fire(Trigger.SteamConnected); break; case EResult.ServiceUnavailable: case EResult.ServiceReadOnly: case EResult.TryAnotherCM: case EResult.AccountLoginDeniedThrottle: case EResult.AlreadyLoggedInElsewhere: case EResult.BadResponse: case EResult.Busy: case EResult.ConnectFailed: _state?.Fire(Trigger.SteamDisconnected); //retry state break; default: _state?.Fire(Trigger.SteamInvalidCreds); break; } }); }
/// <summary> /// Setup the DOTA client callbacks /// </summary> /// <param name="cb"></param> private void SetupDotaClientCallbacks(CallbackManager cb) { cb.Add<DotaGameClient.HandshakeRejected>(rej => { log.ErrorFormat("Connection to the game rejected with reason {0}. Attempts {1}/{2}.", rej.reason, _connAttempts, maxAttempts); }); cb.Add<DotaGameClient.SessionStateTransition>(tra => { log.Debug("[GameClient] "+tra.OldStatus.ToString("G")+" => "+tra.NewStatus.ToString("G")); if (tra.NewStatus == States.PLAY) { _connAttempts = 0; } if (tra.NewStatus != States.DISCONNECTED || _state.State != State.DotaPlay) return; log.WarnFormat("Client has disconnected, attempts {0}/{1}.{2}", _connAttempts, maxAttempts, _connAttempts<maxAttempts ? " Retrying." : " Not retrying."); if (_connAttempts < maxAttempts) StartDotaGameConnection(); }); cb.Add<DotaGameClient.LogMessage>(msg => { log.Debug("[GameClient] "+msg.message); }); }
/// <summary> /// Setup DOTA 2 game coordinator callbacks /// </summary> /// <param name="cb">Manager</param> private void SetupDotaGCCallbacks(CallbackManager cb) { cb.Add<DotaGCHandler.GCWelcomeCallback>(a => { log.Debug("GC session welcomed"); _state.Fire(Trigger.DotaConnected); }); cb.Add<DotaGCHandler.ConnectionStatus>(a => { log.DebugFormat("GC connection status: {0}", a.result.status.ToString("G")); if (a.result.status == GCConnectionStatus.GCConnectionStatus_HAVE_SESSION) _state.Fire(Trigger.DotaConnected); else _state.Fire(Trigger.DotaDisconnected); }); cb.Add<DotaGCHandler.Popup>(a => log.DebugFormat("GC popup message: {0}", a.result.id.ToString("G"))); cb.Add<DotaGCHandler.PracticeLobbySnapshot>(a => HandleLobbyUpdate(a.lobby)); cb.Add<DotaGCHandler.PracticeLobbyLeave>(a => HandleLobbyUpdate(null)); cb.Add<DotaGCHandler.PracticeLobbyUpdate>(a => HandleLobbyUpdate(a.lobby)); cb.Add<DotaGCHandler.JoinChatChannelResponse>(a => { if (DotaGCHandler.Lobby != null && a.result.channel_id != 0 && a.result.channel_name == "Lobby_" + DotaGCHandler.Lobby.lobby_id) lobbyChannelId = a.result.channel_id; }); cb.Add<DotaGCHandler.ChatMessage>( a => { log.DebugFormat("[Chat][" + (a.result.channel_id == lobbyChannelId ? "Lobby" : a.result.channel_id + "") + "] " + a.result.persona_name + ": " + a.result.text); if (a.result.channel_id == lobbyChannelId) { if(a.result.text.Contains("!start")) DotaGCHandler.LaunchLobby(); } }); }
/// <summary> /// Setup steam client callbacks /// </summary> /// <param name="cb"></param> private void SetupSteamCallbacks(CallbackManager cb) { // Handle general connection stuff cb.Add<SteamUser.AccountInfoCallback>(a => { log.DebugFormat("Current name is: {0}, flags {1}, ", a.PersonaName, a.AccountFlags.ToString("G")); UpdatePersona(); }); cb.Add<SteamClient.ConnectedCallback>(a => SteamUser.LogOn(_logonDetails)); cb.Add<SteamClient.DisconnectedCallback>(a => _state.Fire(Trigger.SteamDisconnected)); cb.Add<SteamUser.LoggedOnCallback>(a => { log.DebugFormat("Steam signin result: {0}", a.Result.ToString("G")); switch (a.Result) { case EResult.OK: _state.Fire(Trigger.SteamConnected); break; case EResult.ServiceUnavailable: case EResult.ServiceReadOnly: case EResult.TryAnotherCM: case EResult.AccountLoginDeniedThrottle: case EResult.AlreadyLoggedInElsewhere: case EResult.BadResponse: case EResult.Busy: case EResult.ConnectFailed: _state.Fire(Trigger.SteamDisconnected); //retry state break; default: _state.Fire(Trigger.SteamInvalidCreds); break; } }); }
private void InitAndConnect() { if (client == null) { client = new SteamClient(); DotaGCHandler.Bootstrap(client); user = client.GetHandler<SteamUser>(); friends = client.GetHandler<SteamFriends>(); dota = client.GetHandler<DotaGCHandler>(); manager = new CallbackManager(client); isRunning = true; manager.Add<SteamClient.ConnectedCallback>(c => { if (c.Result != EResult.OK) { fsm.FirePriority(Events.Disconnected); isRunning = false; return; } user.LogOn(details); }); manager.Add<SteamClient.DisconnectedCallback>( c => { fsm?.Fire(Events.Disconnected); }); manager.Add<SteamUser.LoggedOnCallback>(c => { if (c.Result != EResult.OK) { log.Error("Logon failure, result: " + c.Result); switch (c.Result) { case EResult.AccountLogonDenied: fsm.Fire(Events.LogonFailSteamGuard); return; case EResult.ServiceUnavailable: case EResult.TryAnotherCM: fsm.Fire(Events.LogonFailSteamDown); return; } fsm.Fire(Events.LogonFailBadCreds); } else { fsm.Fire(Events.Connected); } }); manager.Add<DotaGCHandler.UnhandledDotaGCCallback>( c => log.Debug("Unknown GC message: " + c.Message.MsgType)); manager.Add<DotaGCHandler.GCWelcomeCallback>( c => fsm.Fire(Events.DotaGCReady)); manager.Add<SteamFriends.FriendsListCallback>(c => log.Debug(c.FriendList)); manager.Add<DotaGCHandler.PracticeLobbySnapshot>(c => { log.DebugFormat("Lobby snapshot received with state: {0}", c.lobby.state); fsm.Fire(c.lobby.state == CSODOTALobby.State.RUN ? Events.DotaEnterLobbyRun : Events.DotaEnterLobbyUI); switch (c.lobby.state) { case CSODOTALobby.State.UI: fsm.FirePriority(Events.DotaEnterLobbyUI); break; case CSODOTALobby.State.RUN: fsm.FirePriority(Events.DotaEnterLobbyRun); break; } LobbyUpdate?.Invoke(c.lobby); }); manager.Add<DotaGCHandler.PingRequest>(c => { log.Debug("GC Sent a ping request. Sending pong!"); dota.Pong(); }); manager.Add<DotaGCHandler.Popup>( c => { log.DebugFormat("Received message (popup) from GC: {0}", c.result.id); }); manager.Add<DotaGCHandler.ConnectionStatus>( c => log.DebugFormat("GC Connection Status: {0}", JObject.FromObject(c.result))); manager.Add<DotaGCHandler.PracticeLobbySnapshot>(c => { log.DebugFormat("Lobby snapshot received with state: {0}", c.lobby.state); if (c.lobby != null) { switch (c.lobby.state) { case CSODOTALobby.State.UI: fsm.FirePriority(Events.DotaEnterLobbyUI); break; case CSODOTALobby.State.RUN: fsm.FirePriority(Events.DotaEnterLobbyRun); break; } } LobbyUpdate?.Invoke(c.lobby); }); } client.Connect(); procThread = new Thread(SteamThread); procThread.Start(this); }