示例#1
0
文件: Client.cs 项目: dkuwahara/D2NG
 /// <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());
 }
示例#2
0
文件: Client.cs 项目: dkuwahara/D2NG
 /// <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);
 }
示例#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);
        }
示例#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);
 }
示例#5
0
文件: Client.cs 项目: inrg/D2NG
 /// <summary>
 /// Leave current game
 /// </summary>
 public void LeaveGame()
 {
     Log.Information("Leaving game");
     D2gs.LeaveGame();
     Bncs.LeaveGame();
     RealmLogon();
     Mcp.CharLogon(_character);
 }
示例#6
0
文件: Client.cs 项目: dkuwahara/D2NG
        /// <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);
        }
示例#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));
 }
示例#8
0
文件: Client.cs 项目: dkuwahara/D2NG
        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}");
        }
示例#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());
        }
示例#10
0
        public void Disconnect()
        {
            if (Bncs.IsConnected())
            {
                Bncs.Disconnect();
            }

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

            if (D2gs.IsConnected())
            {
                D2gs.Disconnect();
            }
        }
示例#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);
        }
示例#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);
        }
示例#13
0
 internal void OnSentPacketEvent(Mcp type, Action <McpPacket> handler)
 => PacketSentEventHandlers.AddOrUpdate(type, handler, (t, h) => h += handler);
示例#14
0
文件: Client.cs 项目: dkuwahara/D2NG
 public void OnSentPacketEvent(Mcp mcp, Action <McpPacket> action)
 => Mcp.OnSentPacketEvent(mcp, action);
示例#15
0
文件: Client.cs 项目: dkuwahara/D2NG
 public void OnReceivedPacketEvent(Mcp mcp, Action <McpPacket> action)
 => Mcp.OnReceivedPacketEvent(mcp, action);
示例#16
0
文件: Client.cs 项目: dkuwahara/D2NG
 private void LeaveGame()
 {
     Bncs.LeaveGame();
     RealmLogon();
     Mcp.CharLogon(_character);
 }