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; new Callback<SteamClient.ConnectedCallback>(c => { if (c.Result != EResult.OK) { fsm.FirePriority(Events.Disconnected); isRunning = false; return; } user.LogOn(details); }, manager); new Callback<SteamClient.DisconnectedCallback>( c => { if (fsm != null) fsm.Fire(Events.Disconnected); }, manager); new Callback<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); new Callback<DotaGCHandler.UnhandledDotaGCCallback>( c => log.Debug("Unknown GC message: " + c.Message.MsgType), manager); new Callback<DotaGCHandler.GCWelcomeCallback>( c => fsm.Fire(Events.DotaGCReady), manager); new Callback<SteamFriends.FriendsListCallback>(c => log.Debug(c.FriendList), manager); new Callback<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); new Callback<DotaGCHandler.PingRequest>(c => { log.Debug("GC Sent a ping request. Sending pong!"); dota.Pong(); }, manager); new Callback<DotaGCHandler.Popup>( c => { log.DebugFormat("Received message (popup) from GC: {0}", c.result.id); }, manager); new Callback<DotaGCHandler.ConnectionStatus>( c => log.DebugFormat("GC Connection Status: {0}", JObject.FromObject(c.result)), manager); new Callback<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); }, manager); } client.Connect(); procThread = new Thread(SteamThread); procThread.Start(this); }
public void Destroy() { manager = null; if (fsm != null) { fsm.Stop(); fsm.ClearExtensions(); fsm = null; } reconnect = false; DisconnectAndCleanup(); user = null; client = null; friends = null; dota = null; manager = null; log.Debug("Bot destroyed."); }