Server serialization functions require client

This commit is contained in:
juanjp600
2016-09-07 17:32:20 -03:00
parent a02931054a
commit bfd8bc6b35
18 changed files with 66 additions and 55 deletions

View File

@@ -14,7 +14,7 @@ namespace Barotrauma.Networking
Default, Error, Dead, Server, Radio
}
class ChatMessage
class ChatMessage : IClientSerializable, IServerSerializable
{
public const float SpeakRange = 2000.0f;
@@ -40,7 +40,11 @@ namespace Barotrauma.Networking
}
public static UInt32 LastID = 0;
public UInt32 ID = 0;
public UInt32 netStateID = 0;
public UInt32 NetStateID
{
get { return netStateID; }
}
private ChatMessage(string senderName, string text, ChatMessageType type, Character sender)
{
@@ -54,7 +58,7 @@ namespace Barotrauma.Networking
TextWithSender = string.IsNullOrWhiteSpace(senderName) ? text : senderName + ": " + text;
LastID++;
ID = LastID;
netStateID = LastID;
}
public static ChatMessage Create(string senderName, string text, ChatMessageType type, Character sender)
@@ -118,5 +122,11 @@ namespace Barotrauma.Networking
return sb.ToString();
}
public void ClientWrite(NetOutgoingMessage msg) { }
public void ServerRead(NetIncomingMessage msg, Client c) { }
public void ServerWrite(NetOutgoingMessage msg, Client c) { }
public void ClientRead(NetIncomingMessage msg) { }
}
}

View File

@@ -27,7 +27,7 @@ namespace Barotrauma.Networking
public CharacterInfo characterInfo;
public NetConnection Connection { get; set; }
public string version;
public bool inGame;
public bool inGame;
public UInt32 lastRecvLobbyUpdate = 0;
public bool hasLobbyData = false;
@@ -52,10 +52,10 @@ namespace Barotrauma.Networking
public ClientPermissions Permissions;
public void InitClientSync()
{
lastSentChatMsgID = 0;
lastRecvChatMsgID = ChatMessage.LastID;
public void InitClientSync()
{
lastSentChatMsgID = 0;
lastRecvChatMsgID = ChatMessage.LastID;
}
public int KickVoteCount

View File

@@ -556,11 +556,11 @@ namespace Barotrauma.Networking
}
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, submarines);
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, submarines);
}
string selectSubName = inc.ReadString();
string selectSubHash = inc.ReadString();
}
string selectSubName = inc.ReadString();
string selectSubHash = inc.ReadString();
GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);
string selectShuttleName = inc.ReadString();
string selectShuttleName = inc.ReadString();
string selectShuttleHash = inc.ReadString();
GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
}
@@ -590,7 +590,7 @@ namespace Barotrauma.Networking
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
outmsg.Write(lastSentChatMsgID);
ChatMessage removeMsg;
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.NetStateID <= lastRecvChatMsgID)) != null)
{
chatMsgQueue.Remove(removeMsg);
}
@@ -598,7 +598,7 @@ namespace Barotrauma.Networking
foreach (ChatMessage cMsg in chatMsgQueue)
{
outmsg.Write((byte)ClientNetObject.CHAT_MESSAGE);
outmsg.Write(cMsg.ID);
outmsg.Write(cMsg.NetStateID);
outmsg.Write(cMsg.Text);
}
outmsg.Write((byte)ClientNetObject.END_OF_MESSAGE);

View File

@@ -636,10 +636,10 @@ namespace Barotrauma.Networking
{
outmsg.Write((UInt16)0);
}
outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).Name);
outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).MD5Hash.ToString());
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name);
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString());
outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).Name);
outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).MD5Hash.ToString());
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name);
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString());
}
else
{
@@ -656,10 +656,10 @@ namespace Barotrauma.Networking
if (gc.UserData is ChatMessage)
{
ChatMessage cMsg = (ChatMessage)gc.UserData;
if (cMsg.ID > c.lastRecvChatMsgID)
if (cMsg.NetStateID > c.lastRecvChatMsgID)
{
outmsg.Write((byte)ServerNetObject.CHAT_MESSAGE);
outmsg.Write(cMsg.ID);
outmsg.Write(cMsg.NetStateID);
outmsg.Write((byte)cMsg.Type);
outmsg.Write(cMsg.SenderName);
outmsg.Write(cMsg.Text);

View File

@@ -1,4 +1,5 @@
using Lidgren.Network;
using System;
using Lidgren.Network;
namespace Barotrauma.Networking
{
@@ -7,10 +8,10 @@ namespace Barotrauma.Networking
/// </summary>
interface IClientSerializable
{
ushort NetStateID { get; }
UInt32 NetStateID { get; }
void ClientWrite(NetOutgoingMessage msg);
void ServerRead(NetIncomingMessage msg);
void ServerRead(NetIncomingMessage msg, Client c);
}
/// <summary>
@@ -18,9 +19,9 @@ namespace Barotrauma.Networking
/// </summary>
interface IServerSerializable
{
ushort NetStateID { get; }
UInt32 NetStateID { get; }
void ServerWrite(NetOutgoingMessage msg);
void ServerWrite(NetOutgoingMessage msg, Client c);
void ClientRead(NetIncomingMessage msg);
}
}