"MessageBox" chatmessage type. Not used in the vanilla game (yet), but custom servers can use it to display custom message boxes at the clients' end. Closes #17
This commit is contained in:
@@ -172,6 +172,7 @@
|
|||||||
<Compile Include="Source\Map\Submarine.cs" />
|
<Compile Include="Source\Map\Submarine.cs" />
|
||||||
<Compile Include="Source\Map\WayPoint.cs" />
|
<Compile Include="Source\Map\WayPoint.cs" />
|
||||||
<Compile Include="Source\Networking\BanList.cs" />
|
<Compile Include="Source\Networking\BanList.cs" />
|
||||||
|
<Compile Include="Source\Networking\ChatMessage.cs" />
|
||||||
<Compile Include="Source\Networking\EntitySpawner.cs" />
|
<Compile Include="Source\Networking\EntitySpawner.cs" />
|
||||||
<Compile Include="Source\Networking\FileTransfer\FileReceiver.cs" />
|
<Compile Include="Source\Networking\FileTransfer\FileReceiver.cs" />
|
||||||
<Compile Include="Source\Networking\GameClient.cs" />
|
<Compile Include="Source\Networking\GameClient.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using Lidgren.Network;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Barotrauma.Networking
|
||||||
|
{
|
||||||
|
partial class ChatMessage
|
||||||
|
{
|
||||||
|
public void ClientWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
||||||
|
msg.Write(NetStateID);
|
||||||
|
msg.Write(Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClientRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
UInt16 ID = msg.ReadUInt16();
|
||||||
|
ChatMessageType type = (ChatMessageType)msg.ReadByte();
|
||||||
|
string txt = msg.ReadString();
|
||||||
|
|
||||||
|
string senderName = "";
|
||||||
|
Character senderCharacter = null;
|
||||||
|
bool hasSenderCharacter = msg.ReadBoolean();
|
||||||
|
if (hasSenderCharacter)
|
||||||
|
{
|
||||||
|
senderCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
|
||||||
|
if (senderCharacter != null)
|
||||||
|
{
|
||||||
|
senderName = senderCharacter.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
senderName = msg.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NetIdUtils.IdMoreRecent(ID, LastID))
|
||||||
|
{
|
||||||
|
if (type == ChatMessageType.MessageBox)
|
||||||
|
{
|
||||||
|
new GUIMessageBox("", txt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter);
|
||||||
|
}
|
||||||
|
LastID = ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,10 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
enum ChatMessageType
|
enum ChatMessageType
|
||||||
{
|
{
|
||||||
Default, Error, Dead, Server, Radio, Private
|
Default, Error, Dead, Server, Radio, Private, MessageBox
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChatMessage
|
partial class ChatMessage
|
||||||
{
|
{
|
||||||
public const int MaxLength = 150;
|
public const int MaxLength = 150;
|
||||||
|
|
||||||
@@ -129,13 +129,6 @@ namespace Barotrauma.Networking
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClientWrite(NetOutgoingMessage msg)
|
|
||||||
{
|
|
||||||
msg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
|
||||||
msg.Write(NetStateID);
|
|
||||||
msg.Write(Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ServerRead(NetIncomingMessage msg, Client c)
|
public static void ServerRead(NetIncomingMessage msg, Client c)
|
||||||
{
|
{
|
||||||
UInt16 ID = msg.ReadUInt16();
|
UInt16 ID = msg.ReadUInt16();
|
||||||
@@ -242,33 +235,5 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ClientRead(NetIncomingMessage msg)
|
|
||||||
{
|
|
||||||
UInt16 ID = msg.ReadUInt16();
|
|
||||||
ChatMessageType type = (ChatMessageType)msg.ReadByte();
|
|
||||||
string txt = msg.ReadString();
|
|
||||||
|
|
||||||
string senderName = "";
|
|
||||||
Character senderCharacter = null;
|
|
||||||
bool hasSenderCharacter = msg.ReadBoolean();
|
|
||||||
if (hasSenderCharacter)
|
|
||||||
{
|
|
||||||
senderCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
|
|
||||||
if (senderCharacter != null)
|
|
||||||
{
|
|
||||||
senderName = senderCharacter.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
senderName = msg.ReadString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NetIdUtils.IdMoreRecent(ID, LastID))
|
|
||||||
{
|
|
||||||
GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter);
|
|
||||||
LastID = ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user