Speidy674 / Light-Reflective-Mirror

A relay transport for mirror.
MIT License
38 stars 9 forks source link

Proccess Data Function Bug #4

Closed Biebras closed 1 year ago

Biebras commented 1 year ago

The current function produces an error if the function tries to process data with a room that does not exist. This can happen for a few seconds when the host disconnects and a client sends a message to the room that does not exist.

These lines throw error:

Room room = _cachedClientRooms[clientId];
if (room != null)
...
Biebras commented 1 year ago

Here is the fix:

private void ProcessData(int clientId, byte[] clientData, int channel, int sendTo = -1)
{
    if(_cachedClientRooms.TryGetValue(clientId, out Room room) == false)
        return;

    if (room.hostId == clientId)
    {
        if (room.clients.Contains(sendTo))
        {
            SendData(clientData, channel, sendTo, clientId);
        }
    }
    else
    {
        SendDataToRoomHost(clientId, clientData, channel, room);
    }
}
Speidy674 commented 1 year ago

fixed whit your PR that merged