static void WebServerOnConnect(int id) { _connectedIds.Add(id); _playerDatas[id] = new PlayerData() { id = (ushort)id }; // Tell new client their id and the game state and everyone's name _bitBuffer.Clear(); _bitBuffer.AddByte(2); _bitBuffer.AddUShort((ushort)id); _bitBuffer.AddByte((byte)_currentState); _bitBuffer.AddUShort((ushort)_playerDatas.Count); foreach (var playerData in _playerDatas.Values) { _bitBuffer.AddUShort(playerData.id); _bitBuffer.AddString(playerData.name); } _bitBuffer.ToArray(_buffer); _webServer.SendOne(id, new ArraySegment <byte>(_buffer, 0, 5 + _playerDatas.Count * 20)); }
private void WebClientOnonConnect() { Debug.Log("Client connected"); _wasConnected = true; // Hide the connect screen ConnectUIController.HideConnectScreen(); // Setup your own nametag LocalPlayerTransform.GetComponent <Nametag>().SetName(ConnectUIController.DisplayName); // Send server your name and potentially some character customization stuff _bitBuffer.Clear(); _bitBuffer.AddByte(8); _bitBuffer.AddString(ConnectUIController.DisplayName); _bitBuffer.ToArray(_buffer); _webClient.Send(new ArraySegment <byte>(_buffer, 0, 22)); }
static void WebServerOnData(int id, ArraySegment <byte> data) { _bitBuffer.Clear(); _bitBuffer.FromArray(data.Array, data.Count); byte messageId = _bitBuffer.ReadByte(); switch (messageId) { case 1: { uint qX = _bitBuffer.ReadUInt(); uint qY = _bitBuffer.ReadUInt(); PlayerData playerData = _playerDatas[id]; playerData.qX = qX; playerData.qY = qY; // Send this position to everyone next state packet _dataToSend.Enqueue(playerData); break; } case 8: { string name = _bitBuffer.ReadString(); _playerDatas[id].name = name; _bitBuffer.Clear(); _bitBuffer.AddByte(9); _bitBuffer.AddUShort(_playerDatas[id].id); _bitBuffer.AddString(_playerDatas[id].name); _bitBuffer.ToArray(_buffer); _webServer.SendAll(_connectedIds, new ArraySegment <byte>(_buffer, 0, 23)); break; } } }
static void WebServerOnData(int id, ArraySegment <byte> data) { _bitBuffer.Clear(); _bitBuffer.FromArray(data.Array, data.Count); byte messageId = _bitBuffer.ReadByte(); switch (messageId) { case 1: { uint qX = _bitBuffer.ReadUInt(); uint qY = _bitBuffer.ReadUInt(); PlayerData playerData = _playerDatas[id]; playerData.qX = qX; playerData.qY = qY; // Send this position to everyone next state packet _dataToSend.Enqueue(playerData); break; } case 8: { string name = _bitBuffer.ReadString(); _playerDatas[id].name = name; _playerDatas[id].handshaked = true; _handshakenClientCount += 1; // Tell new client their id and the game state and everyone's name and points _bitBuffer.Clear(); _bitBuffer.AddByte(2); _bitBuffer.AddUShort((ushort)id); _bitBuffer.AddByte((byte)_currentState); _bitBuffer.AddUShort((ushort)_playerDatas.Count); foreach (var playerData in _playerDatas.Values) { _bitBuffer.AddUShort(playerData.id); _bitBuffer.AddString(playerData.name); _bitBuffer.AddShort(playerData.points); } _bitBuffer.ToArray(_buffer); _webServer.SendOne(id, new ArraySegment <byte>(_buffer, 0, 5 + _playerDatas.Count * 20)); // Tell all the players this new client's name _bitBuffer.Clear(); _bitBuffer.AddByte(9); _bitBuffer.AddUShort(_playerDatas[id].id); _bitBuffer.AddString(_playerDatas[id].name); _bitBuffer.ToArray(_buffer); _webServer.SendAll(_connectedIds, new ArraySegment <byte>(_buffer, 0, 23)); break; } case 10: { ushort objectId = _bitBuffer.ReadUShort(); ushort newX = _bitBuffer.ReadUShort(); ushort newY = _bitBuffer.ReadUShort(); _movedObjects[objectId] = new Tuple <ushort, ushort>(newX, newY); break; } case 11: { short pointChange = _bitBuffer.ReadShort(); _playerDatas[id].points += pointChange; // If points are 0 or less, give builder a point if (pointChange <= 0) { _playerDatas[_builderId].points += 1; } break; } case 12: { _bitBuffer.Clear(); _bitBuffer.AddByte(13); _bitBuffer.AddUShort((ushort)id); _bitBuffer.ToArray(_buffer); _webServer.SendAll(_connectedIds, new ArraySegment <byte>(_buffer, 0, 3)); break; } } }
public void Serialize(BitBuffer bitBuffer) { bitBuffer.AddUShort(7); bitBuffer.AddString(value); }
public void Serialize(BitBuffer bitBuffer) { bitBuffer.AddUShort(3); bitBuffer.AddString(Name); }
public void Serialize(BitBuffer bitBuffer) { bitBuffer.AddUShort(0); bitBuffer.AddString(Message); }