/// <summary> /// Login to Battle.Net with credentials and receive the list of available characters to select. /// </summary> /// <param name="username">Account name</param> /// <param name="password">Password used to login</param> /// <returns>A list of Characters associated with the account</returns> public List <Character> Login(string username, string password) { Bncs.Login(username, password); Log.Information($"Logged in as {username}"); RealmLogon(); return(Mcp.ListCharacters()); }
/// <summary> /// Create a new game /// </summary> /// <param name="difficulty">One of Normal, Nightmare or Hell</param> /// <param name="name">Name of the game to be created</param> /// <param name="password">Password used to protect the game</param> public void CreateGame(Difficulty difficulty, string name, string password) { Log.Information($"Creating {difficulty} game: {name}"); Mcp.CreateGame(difficulty, name, password); Log.Debug($"Game {name} created"); JoinGame(name, password); }
/// <summary> /// Join a game /// </summary> /// <param name="name">Name of the game being joined</param> /// <param name="password">Password used to protect the game</param> public bool JoinGame(string name, string password) { Log.Information($"Joining game: {name} with {LoggedInUserName()}"); var packet = Mcp.JoinGame(name, password); if (packet == null) { return(false); } if (packet.Result != 0x00) { return(false); } Mcp.Disconnect(); Log.Debug($"Connecting to D2GS Server {packet.D2gsIp}"); try { D2gs.Connect(packet.D2gsIp); } catch { D2gs.Disconnect(); return(false); } if (!D2gs.GameLogon(packet.GameHash, packet.GameToken, _character)) { D2gs.Disconnect(); return(false); } Bncs.NotifyJoin(name, password); return(true); }
/// <summary> /// Select one of the available characters on the account. /// </summary> /// <param name="character">Character with name matching one of the account characters</param> public void SelectCharacter(Character character) { Log.Information($"Selecting {character.Name}"); Mcp.CharLogon(character); _character = character; Game.SelectCharacter(character); }
/// <summary> /// Leave current game /// </summary> public void LeaveGame() { Log.Information("Leaving game"); D2gs.LeaveGame(); Bncs.LeaveGame(); RealmLogon(); Mcp.CharLogon(_character); }
/// <summary> /// Join a game /// </summary> /// <param name="name">Name of the game being joined</param> /// <param name="password">Password used to protect the game</param> public void JoinGame(string name, string password) { Log.Information($"Joining game: {name}"); var packet = Mcp.JoinGame(name, password); Mcp.Disconnect(); Log.Debug($"Connecting to D2GS Server {packet.D2gsIp}"); D2gs.Connect(packet.D2gsIp); D2gs.GameLogon(packet.GameHash, packet.GameToken, _character); Bncs.NotifyJoin(name, password); }
/// <summary> /// Create a new game /// </summary> /// <param name="difficulty">One of Normal, Nightmare or Hell</param> /// <param name="name">Name of the game to be created</param> /// <param name="password">Password used to protect the game</param> public bool CreateGame(Difficulty difficulty, string name, string password, string description) { Log.Information($"Creating {difficulty} game: {name}"); if (!Mcp.CreateGame(difficulty, name, password, description)) { Log.Warning($"Creating {difficulty} game: {name} failed"); return(false); } Log.Debug($"Game {name} with {password} created"); return(JoinGame(name, password)); }
private void RealmLogon() { if (_mcpRealm is null) { _mcpRealm = Bncs.ListMcpRealms().First(); } var packet = Bncs.RealmLogon(_mcpRealm); Log.Information($"Connecting to {packet.McpIp}:{packet.McpPort}"); Mcp.Connect(packet.McpIp, packet.McpPort); Mcp.Logon(packet.McpCookie, packet.McpStatus, packet.McpChunk, packet.McpUniqueName); Log.Information($"Connected to {packet.McpIp}:{packet.McpPort}"); }
/// <summary> /// Login to Battle.Net with credentials and receive the list of available characters to select. /// </summary> /// <param name="username">Account name</param> /// <param name="password">Password used to login</param> /// <returns>A list of Characters associated with the account</returns> public List <Character> Login(string username, string password) { if (!Bncs.Login(username, password)) { Log.Warning($"Logged failed as {username}"); return(null); } Log.Information($"Logged in as {username}"); _userName = username; if (!RealmLogon()) { return(null); } return(Mcp.ListCharacters()); }
public void Disconnect() { if (Bncs.IsConnected()) { Bncs.Disconnect(); } if (Mcp.IsConnected()) { Mcp.Disconnect(); } if (D2gs.IsConnected()) { D2gs.Disconnect(); } }
public bool RejoinMCP() { if (Mcp.IsConnected()) { return(true); } Log.Debug("Joining MCP again"); if (!RealmLogon()) { return(false); } var result = Mcp.CharLogon(_character); return(result); }
private bool RealmLogon() { if (_mcpRealm is null) { _mcpRealm = Bncs.ListMcpRealms()?.First(); } if (_mcpRealm == null) { Log.Warning("RealmLogin failed, no mcp realm found"); return(false); } if (!Bncs.IsConnected()) { return(false); } var packet = Bncs.RealmLogon(_mcpRealm); if (packet == null) { Log.Warning("RealmLogin failed"); return(false); } Log.Debug($"Connecting to {packet.McpIp}:{packet.McpPort}"); Mcp.Connect(packet.McpIp, packet.McpPort); if (!Mcp.Logon(packet.McpCookie, packet.McpStatus, packet.McpChunk, packet.McpUniqueName)) { Log.Warning("RealmLogin Connecting failed"); return(false); } Log.Debug($"Connected to MCP {packet.McpIp}:{packet.McpPort}"); return(true); }
internal void OnSentPacketEvent(Mcp type, Action <McpPacket> handler) => PacketSentEventHandlers.AddOrUpdate(type, handler, (t, h) => h += handler);
public void OnSentPacketEvent(Mcp mcp, Action <McpPacket> action) => Mcp.OnSentPacketEvent(mcp, action);
public void OnReceivedPacketEvent(Mcp mcp, Action <McpPacket> action) => Mcp.OnReceivedPacketEvent(mcp, action);
private void LeaveGame() { Bncs.LeaveGame(); RealmLogon(); Mcp.CharLogon(_character); }