public static void Serialize(NetDataWriter writer, SomeVector2 vector) { writer.Put(vector.X); writer.Put(vector.Y); }
public void Serialize(NetDataWriter writer) { writer.Put(UserId); writer.Put(AccessToken); }
public static void PutPackedUInt(this NetDataWriter writer, uint value) { if (value <= 240) { writer.Put((byte)value); return; } if (value <= 2287) { writer.Put((byte)((value - 240) / 256 + 241)); writer.Put((byte)((value - 240) % 256)); return; } if (value <= 67823) { writer.Put((byte)249); writer.Put((byte)((value - 2288) / 256)); writer.Put((byte)((value - 2288) % 256)); return; } if (value <= 16777215) { writer.Put((byte)250); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); return; } // all other values of uint writer.Put((byte)251); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); writer.Put((byte)((value >> 24) & 0xFF)); }
public void Serialize(NetDataWriter writer) { writer.PutPackedLong(connectionId); writer.Put(serverSceneName); }
public void Serialize(NetDataWriter writer) { writer.Put(serverSceneName); }
// private void Update() private void FixedUpdate() { _netClient.PollEvents(); if (OnPeerConnected_ok) { // var peer = _netClient.FirstPeer/* .GetFirstPeer()*/; // if (peer != null && peer.ConnectionState == ConnectionState.Connected) // { last_Distance = Vector3.Distance(last_Networked_Position, player.transform.position); if (last_Distance >= MIN_DISTANCE_TO_SEND_POSITION) { netDataWriter.Reset(); Debug.Log($" ---------------------> FixedUpdate -----> SEND Tags.{NetworkTags.Player_Position} " + $" Position X ={ player.transform.position.x} Y ={ player.transform.position.y} Z = { player.transform.position.z}"); netDataWriter.Put((int)NetworkTags.Player_Position); //Send Local player inputs Online // // // // // // // // // // netDataWriter.Put(player.transform.position.x); netDataWriter.Put(player.transform.position.y); netDataWriter.Put(player.transform.position.z); //netDataWriter.Put(player.transform.position.x); //netDataWriter.Put(player.transform.position.y); //netDataWriter.Put(player.transform.position.z); // // // // // // // // // // // // _netPeer.Send(netDataWriter, DeliveryMethod.Sequenced); last_Networked_Position = player.transform.position; } // } // else // { // //Debug.Log(" ERROR FixedUpdate peer = null = SendDiscoveryRequest"); // _netClient.SendDiscoveryRequest(new byte[] { 1 }, Globals.Serveur_Port); //} foreach (var netPlayer in Dictionary_NetPlayer) { // if (Dictionary_NetPlayer.ContainsKey(netPlayer.Key)) // { if (!netPlayer.Value.GameObjectAdded) { Debug.Log($" ---------------------> FixedUpdate -----> INSTANCIATE new NetPlayerPrefab Id = {netPlayer.Key} " + $"netPlayer.Value.Position X ={ netPlayer.Value.X} Y ={ netPlayer.Value.Y} Z = { netPlayer.Value.Z}"); netPlayer.Value.GameObjectAdded = true; netPlayer.Value.GameObject = Instantiate(Net_Player_GameObject, netPlayer.Value.Position, Quaternion.identity); } else { //Debug.Log($" ---------------------> FixedUpdate -----> POSE UPDATE Id = {netPlayer.Key} " + // $"netPlayer.Value.Position X={netPlayer.Value.X} Y={netPlayer.Value.Y} Z= {netPlayer.Value.Z}"); netPlayer.Value.GameObject.transform.position = netPlayer.Value.Position; } // } } } }
private static void HandleConnection(ConnectionRequest request) { NetDataWriter rejectData = new NetDataWriter(); try { byte result1; byte result2; int position = request.Data.Position; if (!request.Data.TryGetByte(out result1) || !request.Data.TryGetByte(out result2) || result1 != CustomNetworkManager.Major || result2 != CustomNetworkManager.Minor) { rejectData.Reset(); rejectData.Put(3); request.RejectForce(rejectData); } else { if (CustomLiteNetLib4MirrorTransport.IpRateLimiting) { if (CustomLiteNetLib4MirrorTransport.IpRateLimit.Contains(request.RemoteEndPoint.Address.ToString())) { ServerConsole.AddLog(string.Format("Incoming connection from endpoint {0} rejected due to exceeding the rate limit.", request.RemoteEndPoint)); ServerLogs.AddLog(ServerLogs.Modules.Networking, string.Format("Incoming connection from endpoint {0} rejected due to exceeding the rate limit.", request.RemoteEndPoint), ServerLogs.ServerLogType.RateLimit); rejectData.Reset(); rejectData.Put(12); request.RejectForce(rejectData); return; } CustomLiteNetLib4MirrorTransport.IpRateLimit.Add(request.RemoteEndPoint.Address.ToString()); } if (!CharacterClassManager.OnlineMode) { KeyValuePair <BanDetails, BanDetails> keyValuePair = BanHandler.QueryBan(null, request.RemoteEndPoint.Address.ToString()); if (keyValuePair.Value != null) { ServerConsole.AddLog(string.Format("Player tried to connect from banned endpoint {0}.", request.RemoteEndPoint)); rejectData.Reset(); rejectData.Put(6); rejectData.Put(keyValuePair.Value.Expires); rejectData.Put(keyValuePair.Value?.Reason ?? string.Empty); request.RejectForce(rejectData); } else { request.Accept(); } } else { string result3; if (!request.Data.TryGetString(out result3) || result3 == string.Empty) { rejectData.Reset(); rejectData.Put(5); request.RejectForce(rejectData); } else { ulong result4; byte result5; string result6; byte[] result7; if (!request.Data.TryGetULong(out result4) || !request.Data.TryGetByte(out result5) || !request.Data.TryGetString(out result6) || !request.Data.TryGetBytesWithLength(out result7)) { rejectData.Reset(); rejectData.Put(4); request.RejectForce(rejectData); } else { CentralAuthPreauthFlags flags = (CentralAuthPreauthFlags)result5; try { if (!ECDSA.VerifyBytes(string.Format("{0};{1};{2};{3}", result3, result5, result6, result4), result7, ServerConsole.PublicKey)) { ServerConsole.AddLog(string.Format("Player from endpoint {0} sent preauthentication token with invalid digital signature.", request.RemoteEndPoint)); rejectData.Reset(); rejectData.Put(2); request.RejectForce(rejectData); } else if (TimeBehaviour.CurrentUnixTimestamp > result4) { ServerConsole.AddLog(string.Format("Player from endpoint {0} sent expired preauthentication token.", request.RemoteEndPoint)); ServerConsole.AddLog("Make sure that time and timezone set on server is correct. We recommend synchronizing the time."); rejectData.Reset(); rejectData.Put(11); request.RejectForce(rejectData); } else { if (CustomLiteNetLib4MirrorTransport.UserRateLimiting) { if (CustomLiteNetLib4MirrorTransport.UserRateLimit.Contains(result3)) { ServerConsole.AddLog(string.Format("Incoming connection from {0} ({1}) rejected due to exceeding the rate limit.", result3, request.RemoteEndPoint)); ServerLogs.AddLog(ServerLogs.Modules.Networking, string.Format("Incoming connection from endpoint {0} ({1}) rejected due to exceeding the rate limit.", result3, request.RemoteEndPoint), ServerLogs.ServerLogType.RateLimit); rejectData.Reset(); rejectData.Put(12); request.RejectForce(rejectData); return; } CustomLiteNetLib4MirrorTransport.UserRateLimit.Add(result3); } if (!flags.HasFlagFast(CentralAuthPreauthFlags.IgnoreBans) || !ServerStatic.GetPermissionsHandler().IsVerified) { KeyValuePair <BanDetails, BanDetails> keyValuePair = BanHandler.QueryBan(result3, request.RemoteEndPoint.Address.ToString()); if (keyValuePair.Key != null || keyValuePair.Value != null) { ServerConsole.AddLog(string.Format("{0} {1} tried to connect from {2} endpoint {3}.", keyValuePair.Key == null ? "Player" : "Banned player", result3, keyValuePair.Value == null ? "" : "banned ", request.RemoteEndPoint)); ServerLogs.AddLog(ServerLogs.Modules.Networking, string.Format("{0} {1} tried to connect from {2} endpoint {3}.", keyValuePair.Key == null ? "Player" : "Banned player", result3, keyValuePair.Value == null ? "" : "banned ", request.RemoteEndPoint), ServerLogs.ServerLogType.ConnectionUpdate); rejectData.Reset(); rejectData.Put(6); NetDataWriter netDataWriter1 = rejectData; BanDetails key = keyValuePair.Key; netDataWriter1.Put(key != null ? key.Expires : keyValuePair.Value.Expires); NetDataWriter netDataWriter2 = rejectData; string str; if ((str = keyValuePair.Key?.Reason) == null) { str = keyValuePair.Value?.Reason ?? string.Empty; } netDataWriter2.Put(str); request.Reject(rejectData); return; } } if (flags.HasFlagFast(CentralAuthPreauthFlags.GloballyBanned) && !ServerStatic.GetPermissionsHandler().IsVerified) { bool useGlobalBans = CustomLiteNetLib4MirrorTransport.UseGlobalBans; } if ((!flags.HasFlagFast(CentralAuthPreauthFlags.IgnoreWhitelist) || !ServerStatic.GetPermissionsHandler().IsVerified) && !WhiteList.IsWhitelisted(result3)) { ServerConsole.AddLog(string.Format("Player {0} tried joined from endpoint {1}, but is not whitelisted.", result3, request.RemoteEndPoint)); rejectData.Reset(); rejectData.Put(7); request.Reject(rejectData); } else if (CustomLiteNetLib4MirrorTransport.Geoblocking != GeoblockingMode.None && (!flags.HasFlagFast(CentralAuthPreauthFlags.IgnoreGeoblock) || !ServerStatic.GetPermissionsHandler().BanTeamBypassGeo) && (!CustomLiteNetLib4MirrorTransport.GeoblockIgnoreWhitelisted || !WhiteList.IsOnWhitelist(result3)) && (CustomLiteNetLib4MirrorTransport.Geoblocking == GeoblockingMode.Whitelist && !CustomLiteNetLib4MirrorTransport.GeoblockingList.Contains(result6.ToUpper()) || CustomLiteNetLib4MirrorTransport.Geoblocking == GeoblockingMode.Blacklist && CustomLiteNetLib4MirrorTransport.GeoblockingList.Contains(result6.ToUpper()))) { ServerConsole.AddLog(string.Format("Player {0} ({1}) tried joined from blocked country {2}.", result3, request.RemoteEndPoint, result6.ToUpper())); rejectData.Reset(); rejectData.Put(9); request.RejectForce(rejectData); } else { int num = CustomNetworkManager.slots; if (flags.HasFlagFast(CentralAuthPreauthFlags.ReservedSlot) && ServerStatic.GetPermissionsHandler().BanTeamSlots) { num = LiteNetLib4MirrorNetworkManager.singleton.maxConnections; } else if (ConfigFile.ServerConfig.GetBool("use_reserved_slots", true) && ReservedSlot.HasReservedSlot(result3)) { num += CustomNetworkManager.reservedSlots; } if (LiteNetLib4MirrorCore.Host.PeersCount < num) { if (CustomLiteNetLib4MirrorTransport.UserIds.ContainsKey(request.RemoteEndPoint)) { CustomLiteNetLib4MirrorTransport.UserIds[request.RemoteEndPoint].SetUserId(result3); } else { CustomLiteNetLib4MirrorTransport.UserIds.Add(request.RemoteEndPoint, new PreauthItem(result3)); } bool allow = true; Events.InvokePreAuth(result3, request, position, result5, result6, ref allow); if (allow) { request.Accept(); ServerConsole.AddLog(string.Format("Player {0} preauthenticated from endpoint {1}.", result3, request.RemoteEndPoint)); ServerLogs.AddLog(ServerLogs.Modules.Networking, string.Format("{0} preauthenticated from endpoint {1}.", result3, request.RemoteEndPoint), ServerLogs.ServerLogType.ConnectionUpdate); } else { ServerConsole.AddLog(string.Format("Player {0} tried to preauthenticate from endpoint {1}, but the request has been rejected by a plugin.", result3, request.RemoteEndPoint)); ServerLogs.AddLog(ServerLogs.Modules.Networking, string.Format("{0} tried to preauthenticate from endpoint {1}, but the request has been rejected by a plugin.", result3, request.RemoteEndPoint), ServerLogs.ServerLogType.ConnectionUpdate); } } else { rejectData.Reset(); rejectData.Put(1); request.Reject(rejectData); } } } } catch (Exception exception) { Log.Error(string.Format("Player from endpoint {0} sent an invalid preauthentication token. {1}", request.RemoteEndPoint, exception.Message)); rejectData.Reset(); rejectData.Put(2); request.RejectForce(rejectData); } } } } } } catch (Exception exception) { Log.Error(string.Format("Player from endpoint {0} failed to preauthenticate: {1}", request.RemoteEndPoint, exception.Message)); rejectData.Reset(); rejectData.Put(4); request.RejectForce(rejectData); } }
public override void Write(NetDataWriter writer) { writer.Put(PlayerName); }
public override void Write(NetDataWriter writer) { writer.Put(Angle); writer.Put(Time); }
public void Serialize(NetDataWriter writer) { writer.Put(x); writer.Put(y); writer.Put(z); }
public static void SerializeInfo(LiteNetLibElementInfo info, NetDataWriter writer) { writer.PutPackedUInt(info.objectId); writer.Put(info.behaviourIndex); writer.Put(info.elementId); }
public void Run() { Console.WriteLine("=== Broadcast Test ==="); //Server _serverListener = new ServerListener(); NetManager server = new NetManager(_serverListener) { BroadcastReceiveEnabled = true, IPv6Mode = IPv6Mode.DualMode }; if (!server.Start(9050)) { Console.WriteLine("Server start failed"); Console.ReadKey(); return; } _serverListener.Server = server; //Client _clientListener1 = new ClientListener(); NetManager client1 = new NetManager(_clientListener1) { UnconnectedMessagesEnabled = true, SimulateLatency = true, SimulationMaxLatency = 1500, IPv6Mode = IPv6Mode.DualMode }; _clientListener1.Client = client1; if (!client1.Start()) { Console.WriteLine("Client1 start failed"); return; } _clientListener2 = new ClientListener(); NetManager client2 = new NetManager(_clientListener2) { UnconnectedMessagesEnabled = true, SimulateLatency = true, SimulationMaxLatency = 1500, IPv6Mode = IPv6Mode.DualMode }; _clientListener2.Client = client2; client2.Start(); //Send broadcast NetDataWriter writer = new NetDataWriter(); writer.Put("CLIENT 1 DISCOVERY REQUEST"); client1.SendBroadcast(writer, 9050); writer.Reset(); writer.Put("CLIENT 2 DISCOVERY REQUEST"); client2.SendBroadcast(writer, 9050); while (!Console.KeyAvailable) { client1.PollEvents(); client2.PollEvents(); server.PollEvents(); Thread.Sleep(15); } client1.Stop(); client2.Stop(); server.Stop(); Console.ReadKey(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public void Serialize(NetDataWriter writer) { writer.Put(Buttons); writer.Put(Pitch); writer.Put(Yaw); }
public void Serialize(NetDataWriter writer) { writer.Put(value); }
public void Serialize(NetDataWriter writer) { writer.Put(mapId); }
public override void Write(NetDataWriter writer) { writer.Put(Position); writer.Put(Velocity); writer.Put(Input); }
/// <summary> /// Serializates the data. /// </summary> /// <param name="writer">The writer.</param> /// <param name="firstStateUpdate">if set to <c>true</c> it's the first state update.</param> public virtual void TinySerialize(NetDataWriter writer, bool firstStateUpdate) { if (!firstStateUpdate) { //writer.Put((uint)TinyBitArrayUtil.BitArrayToU64(_dirtyFlag)); switch (_dirtyFlag.Length) { case 0: // Do nothing! break; case 8: //byte test = (byte)TinyBitArrayUtil.BitArrayToU64(_dirtyFlag); //Debug.Log("Serialize DirtyFlag: " + test); writer.Put((byte)TinyBitArrayUtil.BitArrayToU64(_dirtyFlag)); break; case 16: writer.Put((ushort)TinyBitArrayUtil.BitArrayToU64(_dirtyFlag)); break; case 32: writer.Put((uint)TinyBitArrayUtil.BitArrayToU64(_dirtyFlag)); break; case 64: writer.Put((ulong)TinyBitArrayUtil.BitArrayToU64(_dirtyFlag)); break; } } //Debug.Log("DirtyFlag: " + _dirtyFlag[0]); //Debug.Log("DirtyFlag: " + TinyBitArrayUtil.Display(_dirtyFlag)); Type type; int maxSyncVar = propertiesName.Length; for (int i = 0; i < maxSyncVar; i++) { if (!firstStateUpdate && _dirtyFlag[i] == false) { continue; } type = propertiesTypes[i]; if (type == typeof(byte)) { writer.Put(byteAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(sbyte)) { writer.Put(sbyteAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(short)) { writer.Put(shortAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(ushort)) { writer.Put(ushortAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(int)) { writer.Put(intAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(uint)) { writer.Put(uintAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(long)) { writer.Put(longAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(ulong)) { writer.Put(ulongAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(float)) { writer.Put(floatAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(double)) { writer.Put(doubleAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(bool)) { writer.Put(boolAccessor[propertiesName[i]].Get(this)); } else if (type == typeof(string)) { writer.Put(stringAccessor[propertiesName[i]].Get(this)); } } }
public override void Write(NetDataWriter writer) { writer.Put((byte)Player); writer.Put(Time); }
public static void Put(this NetDataWriter writer, Vector2 vector) { writer.Put(vector.x); writer.Put(vector.y); }
public override void Write(NetDataWriter writer) { writer.Put((byte)Winner); }
public void Serialize(NetDataWriter writer) { writer.Put((byte)Error); writer.PutValue(Mail); }
public override void Write(NetDataWriter writer) { writer.Put(GameName); writer.Put(MajorVersion); writer.Put(MinorVersion); }
public void Serialize(NetDataWriter writer) { writer.Put((byte)Type); }
public void Serialize(NetDataWriter writer) { writer.Put(timestamp); writer.Put(gameTick); }
public override void Serialize(NetDataWriter writer) { writer.Put(Value); }
public void Serialize(NetDataWriter writer) { writer.Put(MapName); writer.PutValue(BuildingData); }
public static void PutPackedULong(this NetDataWriter writer, ulong value) { if (value <= 240) { writer.Put((byte)value); return; } if (value <= 2287) { writer.Put((byte)((value - 240) / 256 + 241)); writer.Put((byte)((value - 240) % 256)); return; } if (value <= 67823) { writer.Put((byte)249); writer.Put((byte)((value - 2288) / 256)); writer.Put((byte)((value - 2288) % 256)); return; } if (value <= 16777215) { writer.Put((byte)250); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); return; } if (value <= 4294967295) { writer.Put((byte)251); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); writer.Put((byte)((value >> 24) & 0xFF)); return; } if (value <= 1099511627775) { writer.Put((byte)252); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); writer.Put((byte)((value >> 24) & 0xFF)); writer.Put((byte)((value >> 32) & 0xFF)); return; } if (value <= 281474976710655) { writer.Put((byte)253); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); writer.Put((byte)((value >> 24) & 0xFF)); writer.Put((byte)((value >> 32) & 0xFF)); writer.Put((byte)((value >> 40) & 0xFF)); return; } if (value <= 72057594037927935) { writer.Put((byte)254); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); writer.Put((byte)((value >> 24) & 0xFF)); writer.Put((byte)((value >> 32) & 0xFF)); writer.Put((byte)((value >> 40) & 0xFF)); writer.Put((byte)((value >> 48) & 0xFF)); return; } // all others writer.Put((byte)255); writer.Put((byte)(value & 0xFF)); writer.Put((byte)((value >> 8) & 0xFF)); writer.Put((byte)((value >> 16) & 0xFF)); writer.Put((byte)((value >> 24) & 0xFF)); writer.Put((byte)((value >> 32) & 0xFF)); writer.Put((byte)((value >> 40) & 0xFF)); writer.Put((byte)((value >> 48) & 0xFF)); writer.Put((byte)((value >> 56) & 0xFF)); }
public void Serialize(NetDataWriter writer) { writer.Put(ephemeral); writer.Put(unmovable); }
public void Serialize(NetDataWriter writer) { writer.Put(PartyId); }
public void Serialize(NetDataWriter writer) { writer.Put(platformID); writer.Put(mpexVersion); }