Use IPAddress instead of string for IP

This commit is contained in:
UnknownShadow200 2021-05-29 16:23:45 +10:00
parent ca854b8313
commit 683934a6d5
6 changed files with 24 additions and 15 deletions

View File

@ -134,7 +134,7 @@ namespace MCGalaxy.Gui {
}
void dis_lnkHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
Program.OpenBrowser("https://github.com/UnknownShadow200/MCGalaxy/wiki/Discord-relay-bot/");
Program.OpenBrowser(Updater.SourceURL + "/wiki/Discord-relay-bot/");
}
}
}

View File

@ -86,7 +86,7 @@ namespace MCGalaxy.Commands.Maintenance {
p.Message("&W\"{0}\" is not a valid IP address.", args[2]); return;
}
if (who != null) who.ip = args[2];
if (who != null) who.IP = ip;
PlayerDB.Update(args[0], PlayerData.ColumnIP, args[2]);
MessageDataChanged(p, args[0], args[1], args[2]);
} else if (opt == "modified") {

View File

@ -17,6 +17,7 @@
*/
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;
@ -69,7 +70,7 @@ namespace MCGalaxy.Modules.Relay.Discord {
const string host = "gateway.discord.gg";
// stubs
public override bool LowLatency { set { } }
public override string IP { get { return ""; } }
public override IPAddress IP { get { return null; } }
public void Connect() {
client = new TcpClient();

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Network {
public bool Disconnected;
/// <summary> Gets the IP address of the remote end (i.e. client) of the socket. </summary>
public abstract string IP { get; }
public abstract IPAddress IP { get; }
/// <summary> Sets whether this socket operates in low-latency mode (e.g. for TCP, disabes nagle's algorithm). </summary>
public abstract bool LowLatency { set; }
@ -54,7 +54,7 @@ namespace MCGalaxy.Network {
INetProtocol IdentifyProtocol(byte opcode) {
if (opcode == Opcode.Handshake) {
pending.Remove(this);
return new Player() { ip = IP, Socket = this };
return new Player(this);
} else if (opcode == 'G' && Server.Config.WebClient) {
pending.Remove(this);
return new WebSocket(this);
@ -142,8 +142,8 @@ namespace MCGalaxy.Network {
ReceiveNextAsync();
}
public override string IP {
get { return ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(); }
public override IPAddress IP {
get { return ((IPEndPoint)socket.RemoteEndPoint).Address; }
}
public override bool LowLatency { set { socket.NoDelay = value; } }
@ -279,7 +279,7 @@ namespace MCGalaxy.Network {
// Init taken care by underlying socket
public override void Init() { }
public override string IP { get { return s.IP; } }
public override IPAddress IP { get { return s.IP; } }
public override bool LowLatency { set { s.LowLatency = value; } }
protected override void SendRaw(byte[] data, SendFlags flags) {
@ -321,7 +321,7 @@ namespace MCGalaxy.Network {
// Init taken care by underlying socket
public override void Init() { }
public override string IP { get { return raw.IP; } }
public override IPAddress IP { get { return raw.IP; } }
public override bool LowLatency { set { raw.LowLatency = value; } }
public override void Close() { raw.Close(); }
public void Disconnect() { Close(); }

View File

@ -14,6 +14,7 @@ permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.Net;
using MCGalaxy.Drawing;
using MCGalaxy.Drawing.Transforms;
using MCGalaxy.Events.PlayerEvents;
@ -55,7 +56,8 @@ namespace MCGalaxy {
public string DisplayName;
public int warn = 0;
public byte id;
public string ip;
public IPAddress IP;
public string ip { get { return IP.ToString(); } }
public string color;
public Group group;
public LevelPermission hideRank = LevelPermission.Banned;

View File

@ -15,6 +15,7 @@ permissions and limitations under the Licenses.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using MCGalaxy.DB;
@ -54,16 +55,21 @@ namespace MCGalaxy {
//This is so that plugin devs can declare a player without needing a socket..
//They would still have to do p.Dispose()..
public Player(string playername) {
name = playername;
truename = playername;
name = playername;
truename = playername;
DisplayName = playername;
IP = IPAddress.Loopback;
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
IsSuper = true;
IsSuper = true;
}
internal Player() {
internal Player(INetSocket socket) {
Socket = socket;
IP = socket.IP;
spamChecker = new SpamChecker(this);
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
for (int b = 0; b < BlockBindings.Length; b++) {
BlockBindings[b] = (BlockID)b;
}