mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Move Connect to socket to another method in Player class.
This commit is contained in:
parent
0aeaca75fb
commit
e7d57713ec
@ -29,6 +29,10 @@ namespace MCGalaxy.Network {
|
||||
/// <summary> Sets whether this socket operates in low-latency mode (e.g. for TCP, disabes nagle's algorithm). </summary>
|
||||
bool LowLatency { set; }
|
||||
|
||||
/// <summary> Registers receive/send callbacks handlers. </summary>
|
||||
/// <remarks> Separate, to ensure data is only received/sent with a fully constructed object. </remarks>
|
||||
void RegisterCallbacks();
|
||||
|
||||
/// <summary> Receives next block of received data, asynchronously. </summary>
|
||||
void ReceiveNextAsync();
|
||||
|
||||
|
@ -55,7 +55,8 @@ namespace MCGalaxy.Network {
|
||||
bool accepted = false;
|
||||
|
||||
try {
|
||||
p = new Player(listen.socket.EndAccept(result));
|
||||
p = new Player();
|
||||
p.Connect(listen.socket.EndAccept(result));
|
||||
listen.AcceptNextAsync();
|
||||
accepted = true;
|
||||
} catch (Exception ex) {
|
||||
|
@ -48,25 +48,26 @@ namespace MCGalaxy {
|
||||
SuperUser = true;
|
||||
}
|
||||
|
||||
public Player(Socket s) {
|
||||
internal Player() {
|
||||
spamChecker = new SpamChecker(this);
|
||||
try {
|
||||
TcpSocket tcp = new TcpSocket(this, s);
|
||||
Socket = tcp;
|
||||
tcp.RegisterCallbacks();
|
||||
|
||||
ip = Socket.RemoteIP;
|
||||
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
|
||||
Logger.Log(LogType.UserActivity, ip + " connected to the server.");
|
||||
|
||||
for (int i = 0; i < BlockBindings.Length; i++) {
|
||||
BlockBindings[i] = ExtBlock.FromRaw((byte)i);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Connect(Socket s) {
|
||||
try {
|
||||
Socket = new TcpSocket(this, s);
|
||||
ip = Socket.RemoteIP;
|
||||
Socket.RegisterCallbacks();
|
||||
|
||||
Logger.Log(LogType.UserActivity, ip + " connected to the server.");
|
||||
Socket.ReceiveNextAsync();
|
||||
connections.Add(this);
|
||||
} catch ( Exception e ) {
|
||||
Leave("Login failed!"); Logger.LogError(e);
|
||||
}
|
||||
catch ( Exception e ) { Leave("Login failed!"); Logger.LogError(e); }
|
||||
}
|
||||
|
||||
public override byte EntityID { get { return id; } }
|
||||
|
Loading…
x
Reference in New Issue
Block a user