Server name, message and submarine list syncing
This commit is contained in:
@@ -300,6 +300,7 @@ namespace Barotrauma.Networking
|
||||
break;
|
||||
case ServerPacketHeader.UPDATE_LOBBY:
|
||||
//server accepted client
|
||||
ReadLobbyUpdate(inc);
|
||||
CanStart = true;
|
||||
break;
|
||||
}
|
||||
@@ -480,9 +481,9 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
if (!gameStarted)
|
||||
{
|
||||
SendLobbyUpdate();
|
||||
if (!gameStarted)
|
||||
{
|
||||
SendLobbyUpdate();
|
||||
}
|
||||
|
||||
// Update current time
|
||||
@@ -502,66 +503,100 @@ namespace Barotrauma.Networking
|
||||
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
|
||||
|
||||
while ((inc = client.ReadMessage()) != null)
|
||||
{
|
||||
switch (inc.MessageType)
|
||||
{
|
||||
case NetIncomingMessageType.Data:
|
||||
ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte();
|
||||
switch (header)
|
||||
{
|
||||
case ServerPacketHeader.UPDATE_LOBBY:
|
||||
ReadLobbyUpdate(inc);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
{
|
||||
switch (inc.MessageType)
|
||||
{
|
||||
case NetIncomingMessageType.Data:
|
||||
ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte();
|
||||
switch (header)
|
||||
{
|
||||
case ServerPacketHeader.UPDATE_LOBBY:
|
||||
ReadLobbyUpdate(inc);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadLobbyUpdate(NetIncomingMessage inc)
|
||||
{
|
||||
lastRecvChatMsgID = inc.ReadUInt32();
|
||||
|
||||
ServerNetObject objHeader;
|
||||
while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE)
|
||||
{
|
||||
switch (objHeader)
|
||||
{
|
||||
case ServerNetObject.CHAT_MESSAGE:
|
||||
UInt32 ID = inc.ReadUInt32();
|
||||
ChatMessageType type = (ChatMessageType)inc.ReadByte();
|
||||
string senderName = inc.ReadString();
|
||||
string msg = inc.ReadString();
|
||||
if (ID > lastSentChatMsgID)
|
||||
private void ReadLobbyUpdate(NetIncomingMessage inc)
|
||||
{
|
||||
ServerNetObject objHeader;
|
||||
while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE)
|
||||
{
|
||||
switch (objHeader)
|
||||
{
|
||||
case ServerNetObject.SYNC_IDS:
|
||||
bool lobbyUpdated = inc.ReadBoolean();
|
||||
inc.ReadPadBits();
|
||||
if (lobbyUpdated)
|
||||
{
|
||||
AddChatMessage(msg, type, senderName);
|
||||
lastSentChatMsgID = ID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
GameMain.NetLobbyScreen.LastUpdateID = inc.ReadUInt32();
|
||||
GameMain.NetLobbyScreen.ServerName = inc.ReadString();
|
||||
GameMain.NetLobbyScreen.ServerMessage = inc.ReadString();
|
||||
|
||||
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()
|
||||
{
|
||||
NetOutgoingMessage outmsg = client.CreateMessage();
|
||||
outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
||||
|
||||
outmsg.Write(lastSentChatMsgID);
|
||||
ChatMessage removeMsg;
|
||||
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
|
||||
{
|
||||
chatMsgQueue.Remove(removeMsg);
|
||||
}
|
||||
|
||||
foreach (ChatMessage cMsg in chatMsgQueue)
|
||||
{
|
||||
outmsg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
||||
outmsg.Write(cMsg.ID);
|
||||
outmsg.Write(cMsg.Text);
|
||||
}
|
||||
outmsg.Write((byte)ClientNetObject.END_OF_MESSAGE);
|
||||
client.SendMessage(outmsg, NetDeliveryMethod.Unreliable);
|
||||
private void SendLobbyUpdate()
|
||||
{
|
||||
NetOutgoingMessage outmsg = client.CreateMessage();
|
||||
outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
||||
|
||||
outmsg.Write((byte)ClientNetObject.SYNC_IDS);
|
||||
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
|
||||
outmsg.Write(lastSentChatMsgID);
|
||||
ChatMessage removeMsg;
|
||||
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
|
||||
{
|
||||
chatMsgQueue.Remove(removeMsg);
|
||||
}
|
||||
|
||||
foreach (ChatMessage cMsg in chatMsgQueue)
|
||||
{
|
||||
outmsg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
||||
outmsg.Write(cMsg.ID);
|
||||
outmsg.Write(cMsg.Text);
|
||||
}
|
||||
outmsg.Write((byte)ClientNetObject.END_OF_MESSAGE);
|
||||
client.SendMessage(outmsg, NetDeliveryMethod.Unreliable);
|
||||
}
|
||||
|
||||
public override void SendChatMessage(string message, ChatMessageType? type = null)
|
||||
@@ -572,9 +607,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
ChatMessage chatMessage = ChatMessage.Create(
|
||||
gameStarted && myCharacter != null ? myCharacter.Name : name,
|
||||
message, (ChatMessageType)type, gameStarted ? myCharacter : null);
|
||||
|
||||
chatMsgQueue.Add(chatMessage);
|
||||
message, (ChatMessageType)type, gameStarted ? myCharacter : null);
|
||||
|
||||
chatMsgQueue.Add(chatMessage);
|
||||
}
|
||||
|
||||
public bool HasPermission(ClientPermissions permission)
|
||||
|
||||
Reference in New Issue
Block a user