Server name, message and submarine list syncing
This commit is contained in:
@@ -81,7 +81,7 @@ namespace Barotrauma.Networking
|
||||
config.EnableUPnP = true;
|
||||
}
|
||||
|
||||
config.MaximumConnections = maxPlayers;
|
||||
config.MaximumConnections = maxPlayers*2; //double the lidgren connections for unauthenticated players
|
||||
MaxPlayers = maxPlayers;
|
||||
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
|
||||
@@ -466,25 +466,25 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (server.ConnectionsCount > 0)
|
||||
{
|
||||
if (sparseUpdateTimer < DateTime.Now) SparseUpdate();
|
||||
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (gameStarted)
|
||||
{
|
||||
if (c.inGame)
|
||||
{
|
||||
ClientWriteIngame(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientWriteLobby(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientWriteLobby(c);
|
||||
}
|
||||
if (sparseUpdateTimer < DateTime.Now) SparseUpdate();
|
||||
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (gameStarted)
|
||||
{
|
||||
if (c.inGame)
|
||||
{
|
||||
ClientWriteIngame(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientWriteLobby(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientWriteLobby(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,90 +535,129 @@ namespace Barotrauma.Networking
|
||||
userID++;
|
||||
}
|
||||
return userID;
|
||||
}
|
||||
|
||||
private void ClientReadLobby(NetIncomingMessage inc)
|
||||
{
|
||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
if (c == null)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||
return;
|
||||
}
|
||||
|
||||
UInt32 ID = inc.ReadUInt32();
|
||||
if (ID > c.lastRecvChatMsgID)
|
||||
{
|
||||
c.lastRecvChatMsgID = ID;
|
||||
}
|
||||
|
||||
ClientNetObject objHeader;
|
||||
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
||||
{
|
||||
switch (objHeader)
|
||||
{
|
||||
case ClientNetObject.CHAT_MESSAGE:
|
||||
ID = inc.ReadUInt32();
|
||||
string msg = inc.ReadString();
|
||||
if (c.lastSentChatMsgID<ID)
|
||||
}
|
||||
|
||||
private void ClientReadLobby(NetIncomingMessage inc)
|
||||
{
|
||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
if (c == null)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||
return;
|
||||
}
|
||||
|
||||
ClientNetObject objHeader;
|
||||
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
||||
{
|
||||
switch (objHeader)
|
||||
{
|
||||
case ClientNetObject.SYNC_IDS:
|
||||
//TODO: might want to use a clever class for this
|
||||
UInt32 lastLobbyUpdID = inc.ReadUInt32();
|
||||
if (lastLobbyUpdID > c.lastRecvLobbyUpdate)
|
||||
{
|
||||
//this chat message is new to the server
|
||||
AddChatMessage(msg, ChatMessageType.Default, c.name);
|
||||
c.lastSentChatMsgID = ID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c.lastRecvLobbyUpdate = lastLobbyUpdID;
|
||||
}
|
||||
UInt32 lastChatID = inc.ReadUInt32();
|
||||
if (lastChatID > c.lastRecvChatMsgID)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
if (c == null)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||
return;
|
||||
}
|
||||
private void ClientReadIngame(NetIncomingMessage inc)
|
||||
{
|
||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
if (c == null)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClientWriteIngame(Client c)
|
||||
{
|
||||
if (c.Character != null && !c.Character.IsDead)
|
||||
{
|
||||
private void ClientWriteIngame(Client c)
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
outmsg.Write(false);
|
||||
outmsg.WritePadBits();
|
||||
}
|
||||
|
||||
private void ClientWriteLobby(Client c)
|
||||
{
|
||||
NetOutgoingMessage outmsg = server.CreateMessage();
|
||||
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
|
||||
foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children)
|
||||
{
|
||||
if (gc is GUITextBlock)
|
||||
{
|
||||
if (gc.UserData is ChatMessage)
|
||||
{
|
||||
ChatMessage cMsg = (ChatMessage)gc.UserData;
|
||||
if (cMsg.ID > c.lastRecvChatMsgID)
|
||||
{
|
||||
outmsg.Write((byte)ServerNetObject.CHAT_MESSAGE);
|
||||
outmsg.Write(cMsg.ID);
|
||||
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(c.lastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
||||
|
||||
foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children)
|
||||
{
|
||||
if (gc is GUITextBlock)
|
||||
{
|
||||
if (gc.UserData is ChatMessage)
|
||||
{
|
||||
ChatMessage cMsg = (ChatMessage)gc.UserData;
|
||||
if (cMsg.ID > c.lastRecvChatMsgID)
|
||||
{
|
||||
outmsg.Write((byte)ServerNetObject.CHAT_MESSAGE);
|
||||
outmsg.Write(cMsg.ID);
|
||||
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);
|
||||
}
|
||||
|
||||
public bool StartGameClicked(GUIButton button, object obj)
|
||||
|
||||
Reference in New Issue
Block a user