Ejemplo n.º 1
0
 /// <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());
 }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
 /// <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);
 }
Ejemplo n.º 5
0
Archivo: Client.cs Proyecto: inrg/D2NG
 /// <summary>
 /// Leave current game
 /// </summary>
 public void LeaveGame()
 {
     Log.Information("Leaving game");
     D2gs.LeaveGame();
     Bncs.LeaveGame();
     RealmLogon();
     Mcp.CharLogon(_character);
 }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
 /// <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));
 }
Ejemplo n.º 8
0
        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}");
        }
Ejemplo n.º 9
0
        /// <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());
        }
Ejemplo n.º 10
0
        public void Disconnect()
        {
            if (Bncs.IsConnected())
            {
                Bncs.Disconnect();
            }

            if (Mcp.IsConnected())
            {
                Mcp.Disconnect();
            }

            if (D2gs.IsConnected())
            {
                D2gs.Disconnect();
            }
        }
Ejemplo n.º 11
0
        public bool RejoinMCP()
        {
            if (Mcp.IsConnected())
            {
                return(true);
            }

            Log.Debug("Joining MCP again");
            if (!RealmLogon())
            {
                return(false);
            }

            var result = Mcp.CharLogon(_character);

            return(result);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 internal void OnSentPacketEvent(Mcp type, Action <McpPacket> handler)
 => PacketSentEventHandlers.AddOrUpdate(type, handler, (t, h) => h += handler);
Ejemplo n.º 14
0
 public void OnSentPacketEvent(Mcp mcp, Action <McpPacket> action)
 => Mcp.OnSentPacketEvent(mcp, action);
Ejemplo n.º 15
0
 public void OnReceivedPacketEvent(Mcp mcp, Action <McpPacket> action)
 => Mcp.OnReceivedPacketEvent(mcp, action);
Ejemplo n.º 16
0
 private void LeaveGame()
 {
     Bncs.LeaveGame();
     RealmLogon();
     Mcp.CharLogon(_character);
 }