mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-10 04:41:32 -04:00
Prevent inviting an IP address twice, which may cause some issues.
Also fixes a memory leak of unconnected connections.
This commit is contained in:
parent
9d432fbb7b
commit
ae0972c587
@ -500,10 +500,12 @@ pub const ConnectionManager = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addConnection(self: *ConnectionManager, conn: *Connection) void {
|
pub fn addConnection(self: *ConnectionManager, conn: *Connection) error{AlreadyConnected}!void {
|
||||||
self.mutex.lock();
|
self.mutex.lock();
|
||||||
defer self.mutex.unlock();
|
defer self.mutex.unlock();
|
||||||
|
for(self.connections.items) |other| {
|
||||||
|
if(other.remoteAddress.ip == conn.remoteAddress.ip and other.remoteAddress.port == conn.remoteAddress.port) return error.AlreadyConnected;
|
||||||
|
}
|
||||||
self.connections.append(conn);
|
self.connections.append(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1324,7 +1326,7 @@ pub const Connection = struct {
|
|||||||
break :blk settings.defaultPort;
|
break :blk settings.defaultPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
result.manager.addConnection(result);
|
try result.manager.addConnection(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,14 +150,14 @@ fn init(name: []const u8) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deinit() void {
|
fn deinit() void {
|
||||||
for(users.items) |user| {
|
|
||||||
user.decreaseRefCount();
|
|
||||||
}
|
|
||||||
users.clearAndFree();
|
users.clearAndFree();
|
||||||
for(userDeinitList.items) |user| {
|
for(userDeinitList.items) |user| {
|
||||||
user.deinit();
|
user.deinit();
|
||||||
}
|
}
|
||||||
userDeinitList.clearAndFree();
|
userDeinitList.clearAndFree();
|
||||||
|
for(connectionManager.connections.items) |conn| {
|
||||||
|
conn.user.?.decreaseRefCount();
|
||||||
|
}
|
||||||
connectionManager.deinit();
|
connectionManager.deinit();
|
||||||
connectionManager = undefined;
|
connectionManager = undefined;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user