Added lobby chat syncing

This commit is contained in:
juanjp600
2016-09-01 20:45:43 -03:00
parent fc457e0f18
commit 028c3a8bc1
7 changed files with 366 additions and 209 deletions

View File

@@ -354,7 +354,21 @@ namespace Barotrauma.Networking
foreach (Client c in connectedClients)
{
//c.ReliableChannel.Update(deltaTime);
if (gameStarted)
{
if (c.inGame)
{
ClientWriteIngame(c);
}
else
{
}
}
else
{
ClientWriteLobby(c);
}
//slowly reset spam timers
c.ChatSpamTimer = Math.Max(0.0f, c.ChatSpamTimer - deltaTime);
@@ -382,34 +396,31 @@ namespace Barotrauma.Networking
ClientAuthRequest(inc.SenderConnection);
break;
case ClientPacketHeader.REQUEST_INIT:
ClientInitialize(inc);
ClientInitRequest(inc);
break;
case ClientPacketHeader.UPDATE_LOBBY:
//TODO
ClientReadLobby(inc);
break;
case ClientPacketHeader.UPDATE_INGAME_ALIVE:
//TODO
break;
case ClientPacketHeader.UPDATE_INGAME_SPECTATING:
case ClientPacketHeader.UPDATE_INGAME:
//TODO
break;
}
}
break;
case NetIncomingMessageType.StatusChanged:
switch (inc.SenderConnection.Status)
{
case NetConnectionStatus.Disconnected:
var connectedClient = connectedClients.Find(c => c.Connection == inc.SenderConnection);
/*if (connectedClient != null && !disconnectedClients.Contains(connectedClient))
{
connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime;
disconnectedClients.Add(connectedClient);
}
*/
DisconnectClient(inc.SenderConnection,
connectedClient != null ? connectedClient.name + " has disconnected" : "");
break;
switch (inc.SenderConnection.Status)
{
case NetConnectionStatus.Disconnected:
var connectedClient = connectedClients.Find(c => c.Connection == inc.SenderConnection);
/*if (connectedClient != null && !disconnectedClients.Contains(connectedClient))
{
connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime;
disconnectedClients.Add(connectedClient);
}
*/
DisconnectClient(inc.SenderConnection,
connectedClient != null ? connectedClient.name + " has disconnected" : "");
break;
}
break;
case NetIncomingMessageType.ConnectionApproval:
@@ -423,8 +434,8 @@ namespace Barotrauma.Networking
}
else
{
if ((ClientPacketHeader)inc.SenderConnection.RemoteHailMessage.ReadByte() == ClientPacketHeader.REQUEST_AUTH)
{
if ((ClientPacketHeader)inc.SenderConnection.RemoteHailMessage.ReadByte() == ClientPacketHeader.REQUEST_AUTH)
{
inc.SenderConnection.Approve();
ClientAuthRequest(inc.SenderConnection);
}
@@ -522,8 +533,67 @@ 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;
}
ClientNetObject objHeader;
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
{
switch (objHeader)
{
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 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(c.lastSentChatMsgID); //send this to client so they know which messages weren't received by the server
server.SendMessage(outmsg,c.Connection,NetDeliveryMethod.Unreliable);
}
public bool StartGameClicked(GUIButton button, object obj)
{
Submarine selectedSub = null;
@@ -629,13 +699,13 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.Select();
yield return CoroutineStatus.Success;
}
}
public override void KickPlayer(string playerName, bool ban)
{
playerName = playerName.ToLowerInvariant();
Client client = connectedClients.Find(c =>
Client client = connectedClients.Find(c =>
c.name.ToLowerInvariant() == playerName ||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
@@ -644,20 +714,20 @@ namespace Barotrauma.Networking
public void KickClient(NetConnection conn, bool ban = false)
{
Client client = connectedClients.Find(c => c.Connection == conn);
if (client == null)
{
conn.Disconnect(ban ? "You have been banned from the server" : "You have been kicked from the server");
if (ban)
{
if (!banList.IsBanned(conn.RemoteEndPoint.Address.ToString()))
{
banList.BanPlayer("Unnamed", conn.RemoteEndPoint.Address.ToString());
}
}
}
else
{
Client client = connectedClients.Find(c => c.Connection == conn);
if (client == null)
{
conn.Disconnect(ban ? "You have been banned from the server" : "You have been kicked from the server");
if (ban)
{
if (!banList.IsBanned(conn.RemoteEndPoint.Address.ToString()))
{
banList.BanPlayer("Unnamed", conn.RemoteEndPoint.Address.ToString());
}
}
}
else
{
KickClient(client, ban);
}
}
@@ -676,12 +746,12 @@ namespace Barotrauma.Networking
DisconnectClient(client, client.name + " has been kicked from the server", "You have been kicked from the server");
}
}
private void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "")
{
Client client = connectedClients.Find(x => x.Connection == senderConnection);
if (client == null) return;
if (client == null) return;
DisconnectClient(client, msg, targetmsg);
}
@@ -701,10 +771,10 @@ namespace Barotrauma.Networking
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
Log(msg, ChatMessage.MessageColor[(int)ChatMessageType.Server]);
client.Connection.Disconnect(targetmsg);
Log(msg, ChatMessage.MessageColor[(int)ChatMessageType.Server]);
client.Connection.Disconnect(targetmsg);
GameMain.NetLobbyScreen.RemovePlayer(client.name);
connectedClients.Remove(client);