Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/MinecraftClient.suo
/MinecraftClientGUI.v11.suo
/MinecraftClientGUI.suo
/MinecraftClient.userprefs
20 changes: 20 additions & 0 deletions MinecraftClient/Commands/List.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MinecraftClient.Commands
{
public class List : Command
{
public override string CMDName { get { return "list"; } }
public override string CMDDesc { get { return "list: get the player list."; } }

public override string Run(McTcpClient handler, string command)
{
handler.ListPlayers();
return "";
}
}
}

27 changes: 26 additions & 1 deletion MinecraftClient/McTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class McTcpClient : IMinecraftComHandler
private string uuid;
private string sessionid;

public Dictionary<string, string> players;

public int getServerPort() { return port; }
public string getServerHost() { return host; }
public string getUsername() { return username; }
Expand All @@ -56,6 +58,7 @@ public class McTcpClient : IMinecraftComHandler
public McTcpClient(string username, string uuid, string sessionID, int protocolversion, string server_ip, ushort port)
{
StartClient(username, uuid, sessionID, server_ip, port, protocolversion, false, "");
players = new Dictionary<string, string>();
}

/// <summary>
Expand Down Expand Up @@ -388,14 +391,36 @@ public bool SendText(string text)
else return handler.SendChatMessage(text);
}

/// <summary>
/// Display a list of players
/// </summary>
/// <returns>True if the players can be listed</returns>

public bool ListPlayers()
{
ConsoleIO.WriteLine ("Player List");
foreach (string player in players.Values)
ConsoleIO.WriteLine (player);
return true;
}

/// <summary>
/// Allow to respawn after death
/// </summary>
/// <returns>True if packet successfully sent</returns>

public bool SendRespawnPacket()
{
return handler.SendRespawnPacket();
return handler.SendRespawnPacket ();
}

public void addPlayer(string uuid, string name) {
players[uuid] = name;
}
public void removePlayer(string uuid){
players.Remove (uuid);
}

public HashSet<string> getPlayers() { return new HashSet<string>(players.Values); }
}
}
1 change: 1 addition & 0 deletions MinecraftClient/MinecraftClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<Compile Include="Proxy\Handlers\Socks5ProxyClient.cs" />
<Compile Include="Proxy\Handlers\Utils.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Commands\List.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
Expand Down
31 changes: 31 additions & 0 deletions MinecraftClient/Protocol/Handlers/Protocol18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ private bool handlePacket(int packetID, byte[] packetData)
case 0x02:
handler.OnTextReceived(ChatParser.ParseText(readNextString(ref packetData)));
break;
case 0x0C: //Entity Look and Relative Move
//ConsoleIO.WriteLineFormatted("§8 0x0C entity:" + readNextVarInt(ref packetData) + " has come in to sight");
break;
case 0x38: // update player list
int action = readNextVarInt (ref packetData);
int numActions = readNextVarInt (ref packetData);
string uuid = readNextUUID (ref packetData);
switch (action) {
case 0x00:
string name = readNextString (ref packetData);
handler.addPlayer (uuid, name);
break;
case 0x04:
handler.removePlayer (uuid);
break;
default:
//do nothing
break;
}
break;
case 0x3A:
int autocomplete_count = readNextVarInt(ref packetData);
string tab_list = "";
Expand Down Expand Up @@ -256,6 +276,17 @@ private string readNextString(ref byte[] cache)
else return "";
}

/// <summary>
/// Read a uuid from a cache of bytes and remove it from the cache
/// </summary>
/// <param name="cache">Cache of bytes to read from</param>
/// <returns>The uuid as a string</returns>

private string readNextUUID(ref byte[] cache)
{
return BitConverter.ToString(readData (16, ref cache)).Replace ("-", string.Empty).ToLower();
}

/// <summary>
/// Read a byte array from a cache of bytes and remove it from the cache
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions MinecraftClient/Protocol/IMinecraftComHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public interface IMinecraftComHandler
string getUserUUID();
string getSessionID();

void addPlayer(string uuid, string name);
void removePlayer(string uuid);
HashSet<string> getPlayers();

/// <summary>
/// This method is called when the protocol handler receives a chat message
/// </summary>
Expand Down