Merged in paulpach/hlapi-community-edition/norandombytes (pull request #38)

Don't allow end user to send random bytes
This commit is contained in:
Paul Pacheco 2018-07-19 16:14:16 +00:00 committed by vis2k
commit c5263ed7ac

View File

@ -283,7 +283,9 @@ static bool SendToObservers(GameObject contextObj, short msgType, MessageBase ms
return false; return false;
} }
static public void SendWriterToReady(GameObject contextObj, NetworkWriter writer, int channelId) // End users should not send random bytes
// because the other side might interpret them as messages
static internal void SendWriterToReady(GameObject contextObj, NetworkWriter writer, int channelId)
{ {
if (writer.Position > UInt16.MaxValue) if (writer.Position > UInt16.MaxValue)
{ {
@ -293,7 +295,9 @@ static public void SendWriterToReady(GameObject contextObj, NetworkWriter writer
SendBytesToReady(contextObj, writer.ToArray(), writer.Position, channelId); SendBytesToReady(contextObj, writer.ToArray(), writer.Position, channelId);
} }
static public void SendBytesToReady(GameObject contextObj, byte[] buffer, int numBytes, int channelId) // End users should not send random bytes
// because the other side might interpret them as messages
static internal void SendBytesToReady(GameObject contextObj, byte[] buffer, int numBytes, int channelId)
{ {
if (contextObj == null) if (contextObj == null)
{ {
@ -344,25 +348,6 @@ static public void SendBytesToReady(GameObject contextObj, byte[] buffer, int nu
} }
} }
public static void SendBytesToPlayer(GameObject player, byte[] buffer, int numBytes, int channelId)
{
for (int i = 0; i < connections.Count; i++)
{
var conn = connections[i];
if (conn != null)
{
for (int j = 0; j < conn.playerControllers.Count; j++)
{
if (conn.playerControllers[j].IsValid && conn.playerControllers[j].gameObject == player)
{
conn.SendBytes(buffer, numBytes, channelId);
break;
}
}
}
}
}
static public bool SendByChannelToAll(short msgType, MessageBase msg, int channelId) static public bool SendByChannelToAll(short msgType, MessageBase msg, int channelId)
{ {
if (LogFilter.logDev) { Debug.Log("Server.SendByChannelToAll id:" + msgType); } if (LogFilter.logDev) { Debug.Log("Server.SendByChannelToAll id:" + msgType); }