Server name, message and submarine list syncing
This commit is contained in:
@@ -27,8 +27,10 @@ namespace Barotrauma.Networking
|
|||||||
public CharacterInfo characterInfo;
|
public CharacterInfo characterInfo;
|
||||||
public NetConnection Connection { get; set; }
|
public NetConnection Connection { get; set; }
|
||||||
public string version;
|
public string version;
|
||||||
public bool inGame;
|
public bool inGame;
|
||||||
|
public UInt32 lastRecvLobbyUpdate = 0;
|
||||||
|
|
||||||
|
public bool hasLobbyData = false;
|
||||||
public UInt32 lastSentChatMsgID = 0; //last msg this client said
|
public UInt32 lastSentChatMsgID = 0; //last msg this client said
|
||||||
public UInt32 lastRecvChatMsgID = 0; //last msg this client knows about
|
public UInt32 lastRecvChatMsgID = 0; //last msg this client knows about
|
||||||
|
|
||||||
@@ -50,6 +52,12 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public ClientPermissions Permissions;
|
public ClientPermissions Permissions;
|
||||||
|
|
||||||
|
public void InitClientSync()
|
||||||
|
{
|
||||||
|
lastSentChatMsgID = 0;
|
||||||
|
lastRecvChatMsgID = ChatMessage.LastID;
|
||||||
|
}
|
||||||
|
|
||||||
public int KickVoteCount
|
public int KickVoteCount
|
||||||
{
|
{
|
||||||
get { return kickVoters.Count; }
|
get { return kickVoters.Count; }
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
case ServerPacketHeader.UPDATE_LOBBY:
|
case ServerPacketHeader.UPDATE_LOBBY:
|
||||||
//server accepted client
|
//server accepted client
|
||||||
|
ReadLobbyUpdate(inc);
|
||||||
CanStart = true;
|
CanStart = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -480,9 +481,9 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gameStarted)
|
if (!gameStarted)
|
||||||
{
|
{
|
||||||
SendLobbyUpdate();
|
SendLobbyUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update current time
|
// Update current time
|
||||||
@@ -502,66 +503,100 @@ namespace Barotrauma.Networking
|
|||||||
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
|
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
|
||||||
|
|
||||||
while ((inc = client.ReadMessage()) != null)
|
while ((inc = client.ReadMessage()) != null)
|
||||||
{
|
{
|
||||||
switch (inc.MessageType)
|
switch (inc.MessageType)
|
||||||
{
|
{
|
||||||
case NetIncomingMessageType.Data:
|
case NetIncomingMessageType.Data:
|
||||||
ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte();
|
ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte();
|
||||||
switch (header)
|
switch (header)
|
||||||
{
|
{
|
||||||
case ServerPacketHeader.UPDATE_LOBBY:
|
case ServerPacketHeader.UPDATE_LOBBY:
|
||||||
ReadLobbyUpdate(inc);
|
ReadLobbyUpdate(inc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReadLobbyUpdate(NetIncomingMessage inc)
|
private void ReadLobbyUpdate(NetIncomingMessage inc)
|
||||||
{
|
{
|
||||||
lastRecvChatMsgID = inc.ReadUInt32();
|
ServerNetObject objHeader;
|
||||||
|
while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE)
|
||||||
ServerNetObject objHeader;
|
{
|
||||||
while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE)
|
switch (objHeader)
|
||||||
{
|
{
|
||||||
switch (objHeader)
|
case ServerNetObject.SYNC_IDS:
|
||||||
{
|
bool lobbyUpdated = inc.ReadBoolean();
|
||||||
case ServerNetObject.CHAT_MESSAGE:
|
inc.ReadPadBits();
|
||||||
UInt32 ID = inc.ReadUInt32();
|
if (lobbyUpdated)
|
||||||
ChatMessageType type = (ChatMessageType)inc.ReadByte();
|
|
||||||
string senderName = inc.ReadString();
|
|
||||||
string msg = inc.ReadString();
|
|
||||||
if (ID > lastSentChatMsgID)
|
|
||||||
{
|
{
|
||||||
AddChatMessage(msg, type, senderName);
|
GameMain.NetLobbyScreen.LastUpdateID = inc.ReadUInt32();
|
||||||
lastSentChatMsgID = ID;
|
GameMain.NetLobbyScreen.ServerName = inc.ReadString();
|
||||||
}
|
GameMain.NetLobbyScreen.ServerMessage = inc.ReadString();
|
||||||
break;
|
|
||||||
}
|
UInt16 subListCount = inc.ReadUInt16();
|
||||||
}
|
if (subListCount > 0)
|
||||||
|
{
|
||||||
|
List<Submarine> submarines = new List<Submarine>();
|
||||||
|
for (int i = 0; i < subListCount; i++)
|
||||||
|
{
|
||||||
|
string subName = inc.ReadString();
|
||||||
|
string subHash = inc.ReadString();
|
||||||
|
|
||||||
|
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName);
|
||||||
|
if (matchingSub != null)
|
||||||
|
{
|
||||||
|
submarines.Add(matchingSub);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, submarines);
|
||||||
|
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, submarines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastRecvChatMsgID = inc.ReadUInt32();
|
||||||
|
break;
|
||||||
|
case ServerNetObject.CHAT_MESSAGE:
|
||||||
|
UInt32 ID = inc.ReadUInt32();
|
||||||
|
ChatMessageType type = (ChatMessageType)inc.ReadByte();
|
||||||
|
string senderName = inc.ReadString();
|
||||||
|
string msg = inc.ReadString();
|
||||||
|
if (ID > lastSentChatMsgID)
|
||||||
|
{
|
||||||
|
AddChatMessage(msg, type, senderName);
|
||||||
|
lastSentChatMsgID = ID;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendLobbyUpdate()
|
private void SendLobbyUpdate()
|
||||||
{
|
{
|
||||||
NetOutgoingMessage outmsg = client.CreateMessage();
|
NetOutgoingMessage outmsg = client.CreateMessage();
|
||||||
outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
||||||
|
|
||||||
outmsg.Write(lastSentChatMsgID);
|
outmsg.Write((byte)ClientNetObject.SYNC_IDS);
|
||||||
ChatMessage removeMsg;
|
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
|
||||||
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
|
outmsg.Write(lastSentChatMsgID);
|
||||||
{
|
ChatMessage removeMsg;
|
||||||
chatMsgQueue.Remove(removeMsg);
|
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
|
||||||
}
|
{
|
||||||
|
chatMsgQueue.Remove(removeMsg);
|
||||||
foreach (ChatMessage cMsg in chatMsgQueue)
|
}
|
||||||
{
|
|
||||||
outmsg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
foreach (ChatMessage cMsg in chatMsgQueue)
|
||||||
outmsg.Write(cMsg.ID);
|
{
|
||||||
outmsg.Write(cMsg.Text);
|
outmsg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
||||||
}
|
outmsg.Write(cMsg.ID);
|
||||||
outmsg.Write((byte)ClientNetObject.END_OF_MESSAGE);
|
outmsg.Write(cMsg.Text);
|
||||||
client.SendMessage(outmsg, NetDeliveryMethod.Unreliable);
|
}
|
||||||
|
outmsg.Write((byte)ClientNetObject.END_OF_MESSAGE);
|
||||||
|
client.SendMessage(outmsg, NetDeliveryMethod.Unreliable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SendChatMessage(string message, ChatMessageType? type = null)
|
public override void SendChatMessage(string message, ChatMessageType? type = null)
|
||||||
@@ -572,9 +607,9 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
ChatMessage chatMessage = ChatMessage.Create(
|
ChatMessage chatMessage = ChatMessage.Create(
|
||||||
gameStarted && myCharacter != null ? myCharacter.Name : name,
|
gameStarted && myCharacter != null ? myCharacter.Name : name,
|
||||||
message, (ChatMessageType)type, gameStarted ? myCharacter : null);
|
message, (ChatMessageType)type, gameStarted ? myCharacter : null);
|
||||||
|
|
||||||
chatMsgQueue.Add(chatMessage);
|
chatMsgQueue.Add(chatMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasPermission(ClientPermissions permission)
|
public bool HasPermission(ClientPermissions permission)
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace Barotrauma.Networking
|
|||||||
config.EnableUPnP = true;
|
config.EnableUPnP = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.MaximumConnections = maxPlayers;
|
config.MaximumConnections = maxPlayers*2; //double the lidgren connections for unauthenticated players
|
||||||
MaxPlayers = maxPlayers;
|
MaxPlayers = maxPlayers;
|
||||||
|
|
||||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
|
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
|
||||||
@@ -466,25 +466,25 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (server.ConnectionsCount > 0)
|
if (server.ConnectionsCount > 0)
|
||||||
{
|
{
|
||||||
if (sparseUpdateTimer < DateTime.Now) SparseUpdate();
|
if (sparseUpdateTimer < DateTime.Now) SparseUpdate();
|
||||||
|
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in ConnectedClients)
|
||||||
{
|
{
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
if (c.inGame)
|
if (c.inGame)
|
||||||
{
|
{
|
||||||
ClientWriteIngame(c);
|
ClientWriteIngame(c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ClientWriteLobby(c);
|
ClientWriteLobby(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ClientWriteLobby(c);
|
ClientWriteLobby(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,90 +535,129 @@ namespace Barotrauma.Networking
|
|||||||
userID++;
|
userID++;
|
||||||
}
|
}
|
||||||
return userID;
|
return userID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientReadLobby(NetIncomingMessage inc)
|
private void ClientReadLobby(NetIncomingMessage inc)
|
||||||
{
|
{
|
||||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 ID = inc.ReadUInt32();
|
ClientNetObject objHeader;
|
||||||
if (ID > c.lastRecvChatMsgID)
|
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
||||||
{
|
{
|
||||||
c.lastRecvChatMsgID = ID;
|
switch (objHeader)
|
||||||
}
|
{
|
||||||
|
case ClientNetObject.SYNC_IDS:
|
||||||
ClientNetObject objHeader;
|
//TODO: might want to use a clever class for this
|
||||||
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
UInt32 lastLobbyUpdID = inc.ReadUInt32();
|
||||||
{
|
if (lastLobbyUpdID > c.lastRecvLobbyUpdate)
|
||||||
switch (objHeader)
|
|
||||||
{
|
|
||||||
case ClientNetObject.CHAT_MESSAGE:
|
|
||||||
ID = inc.ReadUInt32();
|
|
||||||
string msg = inc.ReadString();
|
|
||||||
if (c.lastSentChatMsgID<ID)
|
|
||||||
{
|
{
|
||||||
//this chat message is new to the server
|
c.lastRecvLobbyUpdate = lastLobbyUpdID;
|
||||||
AddChatMessage(msg, ChatMessageType.Default, c.name);
|
}
|
||||||
c.lastSentChatMsgID = ID;
|
UInt32 lastChatID = inc.ReadUInt32();
|
||||||
}
|
if (lastChatID > c.lastRecvChatMsgID)
|
||||||
break;
|
{
|
||||||
}
|
c.lastRecvChatMsgID = lastChatID;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case ClientNetObject.CHAT_MESSAGE:
|
||||||
|
UInt32 ID = inc.ReadUInt32();
|
||||||
|
string msg = inc.ReadString();
|
||||||
|
if (c.lastSentChatMsgID<ID)
|
||||||
|
{
|
||||||
|
//this chat message is new to the server
|
||||||
|
AddChatMessage(msg, ChatMessageType.Default, c.name);
|
||||||
|
c.lastSentChatMsgID = ID;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientReadIngame(NetIncomingMessage inc)
|
private void ClientReadIngame(NetIncomingMessage inc)
|
||||||
{
|
{
|
||||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientWriteIngame(Client c)
|
private void ClientWriteIngame(Client c)
|
||||||
{
|
{
|
||||||
if (c.Character != null && !c.Character.IsDead)
|
if (c.Character != null && !c.Character.IsDead)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClientWriteLobby(Client c)
|
||||||
|
{
|
||||||
|
NetOutgoingMessage outmsg = server.CreateMessage();
|
||||||
|
outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
|
||||||
|
|
||||||
}
|
outmsg.Write((byte)ServerNetObject.SYNC_IDS);
|
||||||
|
|
||||||
|
if (c.lastRecvLobbyUpdate<GameMain.NetLobbyScreen.LastUpdateID)
|
||||||
|
{
|
||||||
|
outmsg.Write(true);
|
||||||
|
outmsg.WritePadBits();
|
||||||
|
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
|
||||||
|
outmsg.Write(GameMain.NetLobbyScreen.GetServerName());
|
||||||
|
outmsg.Write(GameMain.NetLobbyScreen.ServerMessage);
|
||||||
|
if (c.lastRecvLobbyUpdate < 1)
|
||||||
|
{
|
||||||
|
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||||
|
outmsg.Write((UInt16)subList.Count);
|
||||||
|
for (int i = 0; i < subList.Count; i++)
|
||||||
|
{
|
||||||
|
outmsg.Write(subList[i].Name);
|
||||||
|
outmsg.Write(subList[i].MD5Hash.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outmsg.Write((UInt16)0);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
outmsg.Write(false);
|
||||||
}
|
outmsg.WritePadBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientWriteLobby(Client c)
|
outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
||||||
{
|
|
||||||
NetOutgoingMessage outmsg = server.CreateMessage();
|
foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children)
|
||||||
outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
|
{
|
||||||
outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which messages weren't received by the server
|
if (gc is GUITextBlock)
|
||||||
foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children)
|
{
|
||||||
{
|
if (gc.UserData is ChatMessage)
|
||||||
if (gc is GUITextBlock)
|
{
|
||||||
{
|
ChatMessage cMsg = (ChatMessage)gc.UserData;
|
||||||
if (gc.UserData is ChatMessage)
|
if (cMsg.ID > c.lastRecvChatMsgID)
|
||||||
{
|
{
|
||||||
ChatMessage cMsg = (ChatMessage)gc.UserData;
|
outmsg.Write((byte)ServerNetObject.CHAT_MESSAGE);
|
||||||
if (cMsg.ID > c.lastRecvChatMsgID)
|
outmsg.Write(cMsg.ID);
|
||||||
{
|
outmsg.Write((byte)cMsg.Type);
|
||||||
outmsg.Write((byte)ServerNetObject.CHAT_MESSAGE);
|
outmsg.Write(cMsg.SenderName);
|
||||||
outmsg.Write(cMsg.ID);
|
outmsg.Write(cMsg.Text);
|
||||||
outmsg.Write((byte)cMsg.Type);
|
}
|
||||||
outmsg.Write(cMsg.SenderName);
|
}
|
||||||
outmsg.Write(cMsg.Text);
|
}
|
||||||
}
|
}
|
||||||
}
|
outmsg.Write((byte)ServerNetObject.END_OF_MESSAGE);
|
||||||
}
|
server.SendMessage(outmsg,c.Connection,NetDeliveryMethod.Unreliable);
|
||||||
}
|
|
||||||
outmsg.Write((byte)ServerNetObject.END_OF_MESSAGE);
|
|
||||||
server.SendMessage(outmsg,c.Connection,NetDeliveryMethod.Unreliable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StartGameClicked(GUIButton button, object obj)
|
public bool StartGameClicked(GUIButton button, object obj)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Barotrauma.Networking
|
|||||||
failedAttempts = 0;
|
failedAttempts = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class GameServer : NetworkMember, IPropertyObject
|
partial class GameServer : NetworkMember, IPropertyObject
|
||||||
{
|
{
|
||||||
List<UnauthenticatedClient> unauthenticatedClients = new List<UnauthenticatedClient>();
|
List<UnauthenticatedClient> unauthenticatedClients = new List<UnauthenticatedClient>();
|
||||||
@@ -101,9 +101,10 @@ namespace Barotrauma.Networking
|
|||||||
unauthClient.failedAttempts++;
|
unauthClient.failedAttempts++;
|
||||||
if (unauthClient.failedAttempts > 3)
|
if (unauthClient.failedAttempts > 3)
|
||||||
{
|
{
|
||||||
//disconnect after too many failed attempts
|
//disconnect and ban after too many failed attempts
|
||||||
unauthClient.Connection.Disconnect("Too many failed login attempts.");
|
unauthClient.Connection.Disconnect("Too many failed login attempts. You have been automatically banned from the server.");
|
||||||
unauthenticatedClients.Remove(unauthClient);
|
unauthenticatedClients.Remove(unauthClient);
|
||||||
|
banList.BanPlayer("Unnamed", unauthClient.Connection.RemoteEndPoint.Address.ToString());
|
||||||
unauthClient = null;
|
unauthClient = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -112,7 +113,7 @@ namespace Barotrauma.Networking
|
|||||||
//not disconnecting the player here, because they'll still use the same connection and nonce if they try logging in again
|
//not disconnecting the player here, because they'll still use the same connection and nonce if they try logging in again
|
||||||
NetOutgoingMessage reject = server.CreateMessage();
|
NetOutgoingMessage reject = server.CreateMessage();
|
||||||
reject.Write((byte)ServerPacketHeader.AUTH_FAILURE);
|
reject.Write((byte)ServerPacketHeader.AUTH_FAILURE);
|
||||||
reject.Write("Wrong password!");
|
reject.Write("Wrong password! You have "+Convert.ToString(4-unauthClient.failedAttempts)+" more attempts before you're banned from the server.");
|
||||||
server.SendMessage(reject, unauthClient.Connection, NetDeliveryMethod.Unreliable);
|
server.SendMessage(reject, unauthClient.Connection, NetDeliveryMethod.Unreliable);
|
||||||
unauthClient.AuthTimer = 10.0f;
|
unauthClient.AuthTimer = 10.0f;
|
||||||
return;
|
return;
|
||||||
@@ -171,6 +172,7 @@ namespace Barotrauma.Networking
|
|||||||
//both name and IP address match, replace this player's connection
|
//both name and IP address match, replace this player's connection
|
||||||
nameTaken.Connection.Disconnect("Your session was taken by a new connection on the same IP address.");
|
nameTaken.Connection.Disconnect("Your session was taken by a new connection on the same IP address.");
|
||||||
nameTaken.Connection = unauthClient.Connection;
|
nameTaken.Connection = unauthClient.Connection;
|
||||||
|
nameTaken.InitClientSync(); //reinitialize sync ids because this is a new connection
|
||||||
unauthenticatedClients.Remove(unauthClient);
|
unauthenticatedClients.Remove(unauthClient);
|
||||||
unauthClient = null;
|
unauthClient = null;
|
||||||
return;
|
return;
|
||||||
@@ -187,7 +189,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
//new client
|
//new client
|
||||||
Client newClient = new Client(clName, GetNewClientID());
|
Client newClient = new Client(clName, GetNewClientID());
|
||||||
newClient.lastRecvChatMsgID = ChatMessage.LastID;
|
newClient.InitClientSync();
|
||||||
newClient.Connection = unauthClient.Connection;
|
newClient.Connection = unauthClient.Connection;
|
||||||
unauthenticatedClients.Remove(unauthClient);
|
unauthenticatedClients.Remove(unauthClient);
|
||||||
unauthClient = null;
|
unauthClient = null;
|
||||||
|
|||||||
@@ -16,13 +16,14 @@ namespace Barotrauma.Networking
|
|||||||
UPDATE_LOBBY, //update state in lobby
|
UPDATE_LOBBY, //update state in lobby
|
||||||
UPDATE_INGAME, //update state ingame while alive
|
UPDATE_INGAME, //update state ingame while alive
|
||||||
}
|
}
|
||||||
enum ClientNetObject
|
enum ClientNetObject
|
||||||
{
|
{
|
||||||
END_OF_MESSAGE, //self-explanatory
|
END_OF_MESSAGE, //self-explanatory
|
||||||
CHAT_MESSAGE, //also self-explanatory
|
SYNC_IDS, //ids of the last changes the client knows about
|
||||||
VOTE, //you get the idea
|
CHAT_MESSAGE, //also self-explanatory
|
||||||
CHARACTER_INPUT,
|
VOTE, //you get the idea
|
||||||
ITEM_INTERACTION
|
CHARACTER_INPUT,
|
||||||
|
ITEM_INTERACTION
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ServerPacketHeader
|
enum ServerPacketHeader
|
||||||
@@ -32,13 +33,14 @@ namespace Barotrauma.Networking
|
|||||||
UPDATE_LOBBY, //update state in lobby (votes and chat messages)
|
UPDATE_LOBBY, //update state in lobby (votes and chat messages)
|
||||||
UPDATE_INGAME, //update state ingame while alive (character input and chat messages)
|
UPDATE_INGAME, //update state ingame while alive (character input and chat messages)
|
||||||
}
|
}
|
||||||
enum ServerNetObject
|
enum ServerNetObject
|
||||||
{
|
{
|
||||||
END_OF_MESSAGE,
|
END_OF_MESSAGE,
|
||||||
CHAT_MESSAGE,
|
SYNC_IDS,
|
||||||
VOTE,
|
CHAT_MESSAGE,
|
||||||
CHARACTER_POSITION,
|
VOTE,
|
||||||
ITEM_STATE
|
CHARACTER_POSITION,
|
||||||
|
ITEM_STATE
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VoteType
|
enum VoteType
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Barotrauma
|
|||||||
private GUIListBox subList, modeList, chatBox;
|
private GUIListBox subList, modeList, chatBox;
|
||||||
public GUIListBox ChatBox
|
public GUIListBox ChatBox
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return chatBox;
|
return chatBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,11 +54,21 @@ namespace Barotrauma
|
|||||||
|
|
||||||
const float NetworkUpdateInterval = 1.0f;
|
const float NetworkUpdateInterval = 1.0f;
|
||||||
private float networkUpdateTimer;
|
private float networkUpdateTimer;
|
||||||
private bool valueChanged;
|
private UInt32 lastUpdateID;
|
||||||
|
public UInt32 LastUpdateID
|
||||||
|
{
|
||||||
|
get { if (GameMain.Server != null && lastUpdateID < 1) lastUpdateID++; return lastUpdateID; }
|
||||||
|
set { if (GameMain.Server != null) return; lastUpdateID = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private Sprite backgroundSprite;
|
private Sprite backgroundSprite;
|
||||||
|
|
||||||
private GUITextBox serverMessage;
|
private GUITextBox serverMessage;
|
||||||
|
public string ServerMessage
|
||||||
|
{
|
||||||
|
get { return serverMessage.Text; }
|
||||||
|
set { if (GameMain.Server != null) return; serverMessage.Text = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public GUIListBox SubList
|
public GUIListBox SubList
|
||||||
{
|
{
|
||||||
@@ -559,10 +569,10 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (GameMain.Server == null) return false;
|
if (GameMain.Server == null) return false;
|
||||||
|
|
||||||
GameMain.Server.AutoRestart = tickBox.Selected;
|
GameMain.Server.AutoRestart = tickBox.Selected;
|
||||||
|
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,7 +583,7 @@ namespace Barotrauma
|
|||||||
missionTypeBlock.GetChild<GUITextBlock>().Text = Mission.MissionTypes[missionTypeIndex];
|
missionTypeBlock.GetChild<GUITextBlock>().Text = Mission.MissionTypes[missionTypeIndex];
|
||||||
missionTypeBlock.UserData = missionTypeIndex;
|
missionTypeBlock.UserData = missionTypeIndex;
|
||||||
|
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ToggleMissionType(GUIButton button, object userData)
|
public bool ToggleMissionType(GUIButton button, object userData)
|
||||||
@@ -586,7 +596,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
SetMissionType(missionTypeIndex);
|
SetMissionType(missionTypeIndex);
|
||||||
|
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -601,9 +611,9 @@ namespace Barotrauma
|
|||||||
if (index < 0) index = 2;
|
if (index < 0) index = 2;
|
||||||
if (index > 2) index = 0;
|
if (index > 2) index = 0;
|
||||||
|
|
||||||
SetTraitorsEnabled((YesNoMaybe)index);
|
SetTraitorsEnabled((YesNoMaybe)index);
|
||||||
|
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -628,7 +638,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private bool SelectSub(GUIComponent component, object obj)
|
private bool SelectSub(GUIComponent component, object obj)
|
||||||
{
|
{
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
var hash = obj is Submarine ? ((Submarine)obj).MD5Hash.Hash : "";
|
var hash = obj is Submarine ? ((Submarine)obj).MD5Hash.Hash : "";
|
||||||
|
|
||||||
@@ -654,7 +664,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
subList.ClearChildren();
|
subList.ClearChildren();
|
||||||
|
|
||||||
if (submarines.Count == 0)
|
if (submarines.Count == 0 && GameMain.Server != null)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("No submarines found!");
|
DebugConsole.ThrowError("No submarines found!");
|
||||||
}
|
}
|
||||||
@@ -734,7 +744,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (GameMain.Server == null) return false;
|
if (GameMain.Server == null) return false;
|
||||||
ServerName = text;
|
ServerName = text;
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -742,7 +752,7 @@ namespace Barotrauma
|
|||||||
public bool UpdateServerMessage(GUITextBox textBox, string text)
|
public bool UpdateServerMessage(GUITextBox textBox, string text)
|
||||||
{
|
{
|
||||||
if (GameMain.Server == null) return false;
|
if (GameMain.Server == null) return false;
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -940,18 +950,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
|
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueChanged && GameMain.Server != null)
|
|
||||||
{
|
|
||||||
networkUpdateTimer -= (float)deltaTime;
|
|
||||||
if (networkUpdateTimer <= 0.0f)
|
|
||||||
{
|
|
||||||
GameMain.Server.UpdateNetLobby(null);
|
|
||||||
|
|
||||||
valueChanged = false;
|
|
||||||
networkUpdateTimer = NetworkUpdateInterval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f);
|
//durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f);
|
||||||
}
|
}
|
||||||
@@ -1050,7 +1048,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (modePreset == null) return false;
|
if (modePreset == null) return false;
|
||||||
|
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1061,12 +1059,12 @@ namespace Barotrauma
|
|||||||
if (!string.IsNullOrWhiteSpace(seed))
|
if (!string.IsNullOrWhiteSpace(seed))
|
||||||
{
|
{
|
||||||
LevelSeed = seed;
|
LevelSeed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
//textBox.Text = LevelSeed;
|
//textBox.Text = LevelSeed;
|
||||||
//textBox.Selected = false;
|
//textBox.Selected = false;
|
||||||
|
|
||||||
valueChanged = true;
|
lastUpdateID++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user