private void ProcessStreamedData(int type) { if (!Enum.IsDefined(typeof(ServerMessageType), type)) { Debug.LogFormat("Uknown type 0x{0:x2}.", type); return; } ServerMessageType messageType = (ServerMessageType)type; Debug.LogFormat("0x{0:x2}.", type); ServerMessage message = new ServerMessage(); switch (messageType) { case ServerMessageType.SpheroShoot: ReadStreamedBytes(6); ReadStreamedBytes(buffer[5], 6); SpheroManager.Shoot(buffer); break; case ServerMessageType.RollSphero: ReadStreamedBytes(9); ReadStreamedBytes(buffer[8], 9); SpheroManager.Roll(buffer); break; case ServerMessageType.SpheroPowerUp: ReadStreamedBytes(2); ReadStreamedBytes(buffer[1], 2); SpheroManager.UsePowerUp(buffer); break; case ServerMessageType.AppInit: ReadStreamedBytes(1); Sphero sphero = null; message.Type = ServerMessageType.AppInit; message.AddContent(BitConverter.IsLittleEndian); if (BitConverter.ToBoolean(buffer, 0) && ((sphero = SpheroManager.GetNextSphero()) != null)) { message.AddContent(sphero.DeviceName); } else { message.AddContent(SpheroManager.SpectatorName); //SpectatorManager.Instances.Add(new Spectator(receivedFrom)); } Send(message); if (sphero != null) { sphero.HasController = true; sphero.Connection = this; Debug.LogFormat("Health: {0}", sphero.Health); sphero.SendStateToController(); } break; case ServerMessageType.RemoveSphero: ReadStreamedBytes(1); ReadStreamedBytes(buffer[0], 1); Close(); // SpheroManager.RemoveSphero(buffer); // Server.TcpConnections.Remove(this); break; default: break; } }