private static void ReceiveServerGridPart(byte[] data) { ulong steamId = BitConverter.ToUInt64(data, 0); SegmentedReceiver receiver; if (!_recievers.TryGetValue(steamId, out receiver)) { receiver = new SegmentedReceiver(steamId); _recievers.Add(steamId, receiver); } byte[] message = receiver.Desegment(data); if (message == null) { return; //don't have all the parts yet } ClientData clientData; Utilities.VerifyResult res = Utilities.DeserializeAndVerify(message, out clientData, ServerJump.ServerJumpClass.Instance.Settings.Hub); switch (res) { case Utilities.VerifyResult.Ok: long id = MyAPIGateway.Players.TryGetIdentityId(steamId); Utilities.RecreateFaction(clientData.Faction, id); //create thread for me pls Utilities.FindPositionAndSpawn(clientData.Grid, id, clientData.ControlledBlock); //create thread for me pls SendToClient(MessageType.ResetClient, Encoding.ASCII.GetBytes("pidor"), steamId); //ServerJumpClass.Instance.TryStartLobby(); SendMatchTimes(steamId); break; case Utilities.VerifyResult.Error: MyAPIGateway.Utilities.ShowMessage("Server", "Error loading a grid. Notify an admin!"); MyAPIGateway.Utilities.SendMessage("Error loading a grid. Notify an admin!"); ServerJumpClass.Instance.SomeLog($"User {steamId} failed. Validation response: {res}. Client data to follow:"); ServerJumpClass.Instance.SomeLog(clientData == null ? "NULL" : MyAPIGateway.Utilities.SerializeToXML(clientData)); break; case Utilities.VerifyResult.Timeout: if (ServerJump.ServerJumpClass.Instance.Settings.Hub) { goto case Utilities.VerifyResult.Ok; } goto case Utilities.VerifyResult.ContentModified; case Utilities.VerifyResult.ContentModified: MyAPIGateway.Utilities.SendMessage("A user was detected cheating! Event was recorded and the user will be remnoved from the game."); RedirectClient(steamId, Utilities.ZERO_IP); SendToClient(MessageType.ResetClient, Encoding.ASCII.GetBytes("pidor"), steamId); ServerJumpClass.Instance.SomeLog($"User {steamId} was detected cheating. Validation response: {res}. Client data to follow:"); ServerJumpClass.Instance.SomeLog(clientData == null ? "NULL" : MyAPIGateway.Utilities.SerializeToXML(clientData)); break; default: return; } }
public static void SegmentAndSend(MessageType type, byte[] payload, ulong from, ulong to = 0) { SegmentedReceiver receiver; if (!_recievers.TryGetValue(from, out receiver)) { receiver = new SegmentedReceiver(from); _recievers.Add(from, receiver); } List <byte[]> packets = receiver.Segment(payload); foreach (byte[] packet in packets) { if (to == 0) { SendToServer(type, packet); } else { SendToClient(type, packet, to); } } }
private static void ReceiveClientGridPart(byte[] data) { ulong steamId = BitConverter.ToUInt64(data, 0); SegmentedReceiver receiver; if (!_recievers.TryGetValue(steamId, out receiver)) { receiver = new SegmentedReceiver(steamId); _recievers.Add(steamId, receiver); } byte[] message = receiver.Desegment(data); if (message == null) { return; //don't have all the parts yet } BinaryWriter writer = MyAPIGateway.Utilities.WriteBinaryFileInLocalStorage("Ship.bin", typeof(ServerJumpClass)); writer.Write(message.Length); writer.Write(message); writer.Flush(); writer.Close(); }