private void SendMessageClient() { if (connectedTcpClient == null) { return; } try { // Get a stream object for writing. NetworkStream stream = connectedTcpClient.GetStream(); if (stream.CanWrite) { // string serverMessage = null; // Convert string message to byte array. byte[] serverMessageAsByteArray = ByteHandler.ObjectToByteArray(user); /*Encoding.ASCII.GetBytes(serverMessage);*/ // Write byte array to socketConnection stream. stream.Write(serverMessageAsByteArray, 0, serverMessageAsByteArray.Length); Debug.Log("Server sent his message - should be received by client"); } } catch (SocketException socketException) { Debug.Log("Socket exception: " + socketException); } }
/// <summary> /// Send message to server using socket connection. /// </summary> #region public metods public void SendMessageServer() { if (socketConnection == null) { return; } try { // Get a stream object for writing. NetworkStream stream = socketConnection.GetStream(); if (stream.CanWrite) { // Convert string message to byte array. byte[] clientMessageAsByteArray = ByteHandler.ObjectToByteArray(handler.dataUser); /* Encoding.ASCII.GetBytes(message);*/ // Write byte array to socketConnection stream. stream.Write(clientMessageAsByteArray, 0, clientMessageAsByteArray.Length); Debug.Log("Client sent his message - should be received by server"); } } catch (SocketException socketException) { Debug.Log("Socket exception: " + socketException); } }
/// <summary> /// Runs in background clientReceiveThread; Listens for incomming data. /// </summary> private void ListenForData() { try { socketConnection = new TcpClient("localhost", 8052); Byte[] bytes = new Byte[1024]; while (true) { // Get a stream object for reading using (NetworkStream stream = socketConnection.GetStream()) { int length; // Read incomming stream into byte arrary. while ((length = stream.Read(bytes, 0, bytes.Length)) != 0) { handler.dataUser = ByteHandler.ByteArrayToObject <DataUser>(bytes); } } } } catch (SocketException socketException) { Debug.Log("Socket exception: " + socketException); } }
public Nation Convert(byte[] source) { var nation = new Nation(); nation.Id = ByteHandler.GetIntFromBytes(source, 0); nation.Name = ByteHandler.GetStringFromBytes(source, 4, 50); nation.EUNation = EUNations.Contains(nation.Name, StringComparer.InvariantCultureIgnoreCase); return(nation); }
public Club Convert(byte[] source) { var club = new Club(); club.ClubId = ByteHandler.GetIntFromBytes(source, 0); club.LongName = ByteHandler.GetStringFromBytes(source, 4, 50); club.Name = ByteHandler.GetStringFromBytes(source, 56, 25); club.NationId = ByteHandler.GetIntFromBytes(source, 83); club.DivisionId = ByteHandler.GetIntFromBytes(source, 87); return(club); }
public static void SetConversionProperties(object target, byte[] source) { foreach (var prop in target.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var positionAttribute = (DataFileInfoAttribute)prop.GetCustomAttributes(typeof(DataFileInfoAttribute), true).FirstOrDefault(); if (positionAttribute != null) { prop.SetValue(target, ByteHandler.GetObjectFromBytes(source, positionAttribute.DataFilePosition, prop.PropertyType, positionAttribute.Length, positionAttribute.IsIntrinsic)); } } }
public Club_Comp Convert(byte[] source) { var comp = new Club_Comp(); comp.Id = ByteHandler.GetIntFromBytes(source, 0); comp.LongName = ByteHandler.GetStringFromBytes(source, 4, 50); comp.Name = ByteHandler.GetStringFromBytes(source, 56, 25); //comp.Reputation = ByteHandler.GetByteFromBytes(source, 82); comp.NationId = ByteHandler.GetIntFromBytes(source, 92); comp.Abbreviation = ByteHandler.GetStringFromBytes(source, 83, 3); return(comp); }
public static void SetConversionProperties(object target, PropertyInfo[] props, DataFileInfoAttribute[] attribs, byte[] source) { for (int i = 0; i < props.Length; i++) { var prop = props[i]; var positionAttribute = attribs[i]; if (prop != null && positionAttribute != null) { prop.SetValue(target, ByteHandler.GetObjectFromBytes(source, positionAttribute.DataFilePosition, prop.PropertyType, positionAttribute.Length, positionAttribute.IsIntrinsic)); } } }
private void RegisterBuiltinHandlers() { IntHandler intHandler = new IntHandler(); RegisterBuiltinHandler(Handlers4.IntId, intHandler); RegisterHandlerVersion(intHandler, 0, new IntHandler0()); LongHandler longHandler = new LongHandler(); RegisterBuiltinHandler(Handlers4.LongId, longHandler); RegisterHandlerVersion(longHandler, 0, new LongHandler0()); FloatHandler floatHandler = new FloatHandler(); RegisterBuiltinHandler(Handlers4.FloatId, floatHandler); RegisterHandlerVersion(floatHandler, 0, new FloatHandler0()); BooleanHandler booleanHandler = new BooleanHandler(); RegisterBuiltinHandler(Handlers4.BooleanId, booleanHandler); // TODO: Are we missing a boolean handler version? DoubleHandler doubleHandler = new DoubleHandler(); RegisterBuiltinHandler(Handlers4.DoubleId, doubleHandler); RegisterHandlerVersion(doubleHandler, 0, new DoubleHandler0()); ByteHandler byteHandler = new ByteHandler(); RegisterBuiltinHandler(Handlers4.ByteId, byteHandler); // TODO: Are we missing a byte handler version? CharHandler charHandler = new CharHandler(); RegisterBuiltinHandler(Handlers4.CharId, charHandler); // TODO: Are we missing a char handler version? ShortHandler shortHandler = new ShortHandler(); RegisterBuiltinHandler(Handlers4.ShortId, shortHandler); RegisterHandlerVersion(shortHandler, 0, new ShortHandler0()); _stringHandler = new StringHandler(); RegisterBuiltinHandler(Handlers4.StringId, _stringHandler); RegisterHandlerVersion(_stringHandler, 0, new StringHandler0()); DateHandler dateHandler = new DateHandler(); RegisterBuiltinHandler(Handlers4.DateId, dateHandler); RegisterHandlerVersion(dateHandler, 0, new DateHandler0()); RegisterUntypedHandlers(); RegisterCompositeHandlerVersions(); }
private void ListenForIncommingRequests() { try { // Create listener on localhost port 8052. tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8052); tcpListener.Start(); Debug.Log("Server is listening"); byte[] bytes = new byte[1024]; while (true) { using (connectedTcpClient = tcpListener.AcceptTcpClient()) { // Get a stream object for reading using (NetworkStream stream = connectedTcpClient.GetStream()) { int length; // Read incomming stream into byte arrary. while ((length = stream.Read(bytes, 0, bytes.Length)) != 0) { var getData = ByteHandler.ByteArrayToObject <DataUser>(bytes); if (getData.Entry == Entry.SignUp) { user = getData; } else if (getData.Entry == Entry.SignIn && HandlerValidate.IsValidateData(user, getData)) { user.IsActivePanel = true; SendMessageClient(); } } } } } } catch (SocketException socketException) { Debug.Log("SocketException " + socketException.ToString()); } }
public static object TryCast(string type, object value, Dictionary <string, byte> variables) { if (IsPrimitive(type)) { switch (type) { case "byte": return(ByteHandler.Cast(value, variables)); case "int": return((int)value); case "long": return((long)value); case "angle": return(CastToAngle(value)); case "string": return((string)value); case "bool": return((bool)value); case "float": return((float)value); case "double": return((double)value); case "precise": return(CastToPrecise(value)); } } if (value is CatCompoundObject cco) { var obj = cco.TypeClass; while (null != obj.Parent && obj.Name != type) { obj = obj.Parent; } if (obj.Name == type) { return(obj); } } throw new NullReferenceException(); }
public Staff Convert(byte[] source) { var staff = new Staff(); staff.StaffId = ByteHandler.GetIntFromBytes(source, 0); staff.StaffPlayerId = ByteHandler.GetIntFromBytes(source, 97); staff.FirstNameId = ByteHandler.GetIntFromBytes(source, 4); staff.SecondNameId = ByteHandler.GetIntFromBytes(source, 8); staff.CommonNameId = ByteHandler.GetIntFromBytes(source, 12); staff.DOB = ByteHandler.GetDateFromBytes(source, 16) ?? new DateTime(1985, 1, 1); staff.NationId = ByteHandler.GetIntFromBytes(source, 26); staff.SecondaryNationId = ByteHandler.GetIntFromBytes(source, 30); staff.InternationalCaps = ByteHandler.GetByteFromBytes(source, 24); staff.InternationalGoals = ByteHandler.GetByteFromBytes(source, 25); staff.ContractExpiryDate = ByteHandler.GetDateFromBytes(source, 70); staff.Wage = ByteHandler.GetIntFromBytes(source, 78); staff.Value = ByteHandler.GetIntFromBytes(source, 82); staff.ClubId = ByteHandler.GetIntFromBytes(source, 57); List <int> playerTests = new List <int>() { 11282, 35425, 70038, 21195, 120511, 16406 }; if (playerTests.Contains(staff.StaffPlayerId)) { var dobBytes = string.Join(", ", source.Skip(16).Take(5)); var epiryBytes = string.Join(", ", source.Skip(70).Take(5)); } staff.Adaptability = ByteHandler.GetByteFromBytes(source, 86); staff.Ambition = ByteHandler.GetByteFromBytes(source, 87); staff.Determination = ByteHandler.GetByteFromBytes(source, 88); staff.Loyalty = ByteHandler.GetByteFromBytes(source, 89); staff.Pressure = ByteHandler.GetByteFromBytes(source, 90); staff.Professionalism = ByteHandler.GetByteFromBytes(source, 91); staff.Sportsmanship = ByteHandler.GetByteFromBytes(source, 92); staff.Temperament = ByteHandler.GetByteFromBytes(source, 93); return(staff); }
public Contract Convert(byte[] source) { var contract = new Contract(); contract.PlayerId = ByteHandler.GetIntFromBytes(source, 0); contract.WagePerWeek = (int)(ByteHandler.GetIntFromBytes(source, 12) * _valueMultiplier); contract.GoalBonus = (int)(ByteHandler.GetIntFromBytes(source, 16) * _valueMultiplier); contract.AssistBonus = (int)(ByteHandler.GetIntFromBytes(source, 20) * _valueMultiplier); contract.NonPromotionReleaseClause = ByteHandler.GetByteFromBytes(source, 28) == 1; contract.MinimumFeeReleaseClause = ByteHandler.GetByteFromBytes(source, 29) == 1; contract.NonPlayingReleaseClause = ByteHandler.GetByteFromBytes(source, 30) == 1; contract.RelegationReleaseClause = ByteHandler.GetByteFromBytes(source, 31) == 1; contract.ManagerReleaseClause = ByteHandler.GetByteFromBytes(source, 32) == 1; contract.ReleaseClauseValue = (int)(ByteHandler.GetIntFromBytes(source, 33) * _valueMultiplier); contract.ContractStartDate = ByteHandler.GetDateFromBytes(source, 37); contract.ContractEndDate = ByteHandler.GetDateFromBytes(source, 45); contract.TransferStatus = ByteHandler.GetByteFromBytes(source, 78); contract.SquadStatus = ByteHandler.GetByteFromBytes(source, 79); return(contract); }
public PlayerData Convert(byte[] source) { var player = new PlayerData(); player.PlayerId = ByteHandler.GetIntFromBytes(source, 0); player.CurrentAbility = ByteHandler.GetShortFromBytes(source, 5); player.PotentialAbility = ByteHandler.GetShortFromBytes(source, 7); player.Reputation = ByteHandler.GetShortFromBytes(source, 9); player.DomesticReputation = ByteHandler.GetShortFromBytes(source, 11); player.WorldReputation = ByteHandler.GetShortFromBytes(source, 13); player.GK = ByteHandler.GetByteFromBytes(source, 15); player.SW = ByteHandler.GetByteFromBytes(source, 16); player.DF = ByteHandler.GetByteFromBytes(source, 17); player.DM = ByteHandler.GetByteFromBytes(source, 18); player.MF = ByteHandler.GetByteFromBytes(source, 19); player.AM = ByteHandler.GetByteFromBytes(source, 20); player.ST = ByteHandler.GetByteFromBytes(source, 21); player.WingBack = ByteHandler.GetByteFromBytes(source, 22); player.Left = ByteHandler.GetByteFromBytes(source, 24); player.Right = ByteHandler.GetByteFromBytes(source, 23); player.Centre = ByteHandler.GetByteFromBytes(source, 25); player.FreeRole = ByteHandler.GetByteFromBytes(source, 26); player.Acceleration = ByteHandler.GetByteFromBytes(source, 27); player.Aggression = ByteHandler.GetByteFromBytes(source, 28); player.Agility = ByteHandler.GetByteFromBytes(source, 29); player.Anticipation = ByteHandler.GetByteFromBytes(source, 30, true); player.Balance = ByteHandler.GetByteFromBytes(source, 31); player.Bravery = ByteHandler.GetByteFromBytes(source, 32); player.Consistency = ByteHandler.GetByteFromBytes(source, 33); player.Corners = ByteHandler.GetByteFromBytes(source, 34); player.Creativity = ByteHandler.GetByteFromBytes(source, 67, true); player.Crossing = ByteHandler.GetByteFromBytes(source, 35, true); player.Decisions = ByteHandler.GetByteFromBytes(source, 36, true); player.Dirtiness = ByteHandler.GetByteFromBytes(source, 37); player.Dribbling = ByteHandler.GetByteFromBytes(source, 38, true); player.Finishing = ByteHandler.GetByteFromBytes(source, 39, true); player.Flair = ByteHandler.GetByteFromBytes(source, 40); player.FreeKicks = ByteHandler.GetByteFromBytes(source, 41); player.Handling = ByteHandler.GetByteFromBytes(source, 42, true); player.Heading = ByteHandler.GetByteFromBytes(source, 43, true); player.ImportantMatches = ByteHandler.GetByteFromBytes(source, 44); player.Influence = ByteHandler.GetByteFromBytes(source, 47); player.InjuryProneness = ByteHandler.GetByteFromBytes(source, 45); player.Jumping = ByteHandler.GetByteFromBytes(source, 46); player.LongShots = ByteHandler.GetByteFromBytes(source, 49, true); player.Marking = ByteHandler.GetByteFromBytes(source, 50, true); player.NaturalFitness = ByteHandler.GetByteFromBytes(source, 52); player.OffTheBall = ByteHandler.GetByteFromBytes(source, 51, true); player.OneOnOnes = ByteHandler.GetByteFromBytes(source, 53, true); player.Pace = ByteHandler.GetByteFromBytes(source, 54); player.Passing = ByteHandler.GetByteFromBytes(source, 55, true); player.Penalties = ByteHandler.GetByteFromBytes(source, 56, true); player.Positioning = ByteHandler.GetByteFromBytes(source, 57, true); player.Reflexes = ByteHandler.GetByteFromBytes(source, 58, true); player.Stamina = ByteHandler.GetByteFromBytes(source, 60); player.Strength = ByteHandler.GetByteFromBytes(source, 61); player.Tackling = ByteHandler.GetByteFromBytes(source, 62, true); player.Teamwork = ByteHandler.GetByteFromBytes(source, 63); player.Technique = ByteHandler.GetByteFromBytes(source, 64); player.ThrowIns = ByteHandler.GetByteFromBytes(source, 65, true); player.Versatility = ByteHandler.GetByteFromBytes(source, 66); player.WorkRate = ByteHandler.GetByteFromBytes(source, 68); player.LeftFoot = ByteHandler.GetByteFromBytes(source, 48); player.RightFoot = ByteHandler.GetByteFromBytes(source, 59); return(player); }
public static INumberHandler Get(Type type) { INumberHandler result; if (!handlers.TryGetValue(type, out result)) { if (type == typeof(int)) { result = new IntHandler(); } else if (type == typeof(float)) { result = new FloatHandler(); } else if (type == typeof(long)) { result = new LongHandler(); } else if (type == typeof(double)) { result = new DoubleHandler(); } else if (type == typeof(byte)) { result = new ByteHandler(); } else if (type == typeof(char)) { result = new CharHandler(); } else if (type == typeof(short)) { result = new ShortHandler(); } else if (type == typeof(uint)) { result = new UIntHandler(); } else if (type == typeof(ulong)) { result = new ULongHandler(); } else if (type == typeof(sbyte)) { result = new SByteHandler(); } else if (type == typeof(ushort)) { result = new UShortHandler(); } else if (type == typeof(decimal)) { result = new DecimalHandler(); } else { result = null; } handlers[type] = result; } return(result); }