protected async void HandshakeHandler(NeutronPlayer player, double clientTime, Authentication authentication) { if (authentication.Pass.Decrypt(out string phrase)) { authentication = new Authentication(authentication.User, phrase, false); try { if (await OnAuthentication.Invoke(player, authentication)) //* First packet { using (NeutronStream stream = Neutron.PooledNetworkStreams.Pull()) //* Second First packet { NeutronStream.IWriter writer = stream.Writer; writer.WritePacket((byte)Packet.Handshake); writer.Write(LocalTime); writer.Write(clientTime); writer.Write(player.StateObject.UdpLocalEndPoint.Port); writer.WriteWithInteger(player); player.Write(writer); } OnPlayerConnected?.Invoke(player); //* Three packet } } catch (Exception ex) // Tasks manual catch exception. { LogHelper.Stacktrace(ex); } } else if (!LogHelper.Error("Auth decrypt failed!")) { DisconnectHandler(player); } }
public void SpawnPlayer(int iD, string username, Vector3 position, bool isFacingRight, bool isDead, bool justJoined) { GameObject player; GameObject prefab; bool localClient = iD == Client.Instance.ClientID; if (localClient) { if (IsMobileSupported()) { prefab = MobileLocalPlayerPrefab; } else { prefab = LocalPlayerPrefab; } Debug.Log($"You, player: {iD} have been spawned."); } else { prefab = PlayerPrefab; Debug.Log($"Player: {iD} has been spawned."); } player = Instantiate(prefab, position, Quaternion.identity); PlayerManager playerManager = player.GetComponent <PlayerManager>(); playerManager.Initialise(iD, username); PlayerDictionary.Add(iD, playerManager); NonLocalPlayerHealth healthManager = player.GetComponentInChildren <NonLocalPlayerHealth>(); healthManager?.SetOwnerClientID(iD); NonLocalPlayerMovement playerMovement = player.GetComponentInChildren <NonLocalPlayerMovement>(); playerMovement?.SetOwnerClientID(iD); NonLocalPlayerAnimations playerAnimations = player.GetComponentInChildren <NonLocalPlayerAnimations>(); playerAnimations?.SetOwnerClientID(iD); IGun playerGun = player.GetComponentInChildren <IGun>(); playerGun?.SetOwnerClientID(iD); if (!isFacingRight) { playerAnimations.FlipSprite(); } StartCoroutine(playerManager.IsPlayerDeadUponSpawning(isDead)); OnPlayerConnected?.Invoke(iD, username, justJoined); }
public PhotonService(IRuntimeService runtimeService) { _runtimeService = runtimeService; _photonClient = runtimeService.RegisterClient <PhotonCallbacksClient>(); _photonClient.OnPlayerConnected += p => OnPlayerConnected?.Invoke(p); _photonClient.OnPlayerDisconnected += p => OnPlayerDisconnected?.Invoke(p); Connect(); }
private void HandlePlayerConnected() { var player = ConnectedServer.ReadDataPlayer(lobbyReader); if (!Chat.MutedPlayers.ContainsKey(player.IPAddress)) { Chat.MutedPlayers.Add(player.IPAddress, false); } OnPlayerConnected.Invoke(player); }
/// <summary> /// Handles the player joined message /// </summary> /// <param name="inMsg">The message to decode</param> private void HandlePlayerJoined(NetIncomingMessage inMsg) { byte playerId = inMsg.ReadByte(); string name = inMsg.ReadString(); bool isBot = inMsg.ReadBoolean(); bool isHost = inMsg.ReadBoolean(); inMsg.ReadPadBits(); myKnownPlayers[playerId] = new Player(playerId, name, isBot); myKnownPlayers[playerId].IsHost = isHost; OnPlayerConnected?.Invoke(this, myKnownPlayers[playerId]); }
private void HandleConnected(NetIncomingMessage message) { string username = _connectionToUsername[message.SenderConnection]; int serverNameLength = _settingsService.ServerName.Length > 32 ? 32 : _settingsService.ServerName.Length; int announcementLength = _settingsService.Announcement.Length > 255 ? 255 : _settingsService.Announcement.Length; ConnectedToServerPacket response = new ConnectedToServerPacket { ServerName = _settingsService.ServerName.Substring(0, serverNameLength), AllowCharacterDeletion = _settingsService.AllowCharacterDeletion, Announcement = _settingsService.Announcement.Substring(0, announcementLength), Category = _settingsService.GameCategory, CurrentPlayers = _usernameToConnection.Count, MaxPlayers = _settingsService.MaxPlayers, PVP = _settingsService.PVPType, RequiredResourcePacks = _moduleService.GetLoadedModuleData().ResourcePacks }; string directoryPath = _pathService.ServerVaultDirectory + "/" + username + "/"; if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } string[] files = Directory.GetFiles(_pathService.ServerVaultDirectory + "/" + username + "/", "*.pcf"); foreach (string pcFile in files) { PCData pc = _dataService.Load <PCData>(pcFile); PCTransferObject pcTO = PCTransferObject.Load(pc); response.PCs.Add(pcTO); } SendMessage(PacketDeliveryMethod.ReliableUnordered, response, username); OnPlayerConnected?.Invoke(username); }
public void InvokePlayerConnected(ConnectedClient client) => OnPlayerConnected?.Invoke(client);
internal static void RunPlayerConnected(SteamPlayer player) => OnPlayerConnected?.Invoke(UnturnedPlayer.Create(player));
public static void PlayerConnect(Player player) { OnPlayerConnected?.Invoke(player); }
internal static void HandlePlayerConnection(BasePlayer player) { OnPlayerConnected?.TryInvoke(player); }
private void PlayerConnected(NetworkClient player) { OnPlayerConnected?.Invoke(player); }
private void PlayerConnected(string username) { OnPlayerConnected?.Invoke(username); }
public void RaisePlayerConnected(IPlayer player) { OnPlayerConnected?.Invoke(player); }
public override void OnPlayerEnteredRoom(Player newPlayer) { Debug.Log($"On Photon Player connected ID {newPlayer.ActorNumber}."); OnPlayerConnected?.Invoke(CreatePlayerID(newPlayer.ActorNumber)); }
public override void OnConnectedToMaster() { OnPlayerConnected?.Invoke(); Debug.Log("<color=red>Player connected to master</color>"); }
Message GetMessage() { if (gotMessages.Count != 0) { return(gotMessages.Dequeue()); } NetIncomingMessage message; while ((message = netPeer.ReadMessage()) != null) { switch (message.MessageType) { case NetIncomingMessageType.Data: string sender = message.ReadString(); int size = message.ReadInt32(); object msg = Serializer.FromBytes <object>(message.ReadBytes(size)); if (msg is ConnectMessage && Server) { var connectMsg = (ConnectMessage)msg; if (connections.ContainsKey(sender)) { // TODO GET OUT break; } connections[sender] = message.SenderConnection; SendPlayersInfo(); OnPlayerConnected?.Invoke(sender); break; } if (msg is PlayersInfo && !Server) { var info = (PlayersInfo)msg; players = new HashSet <string>(info.players); _connected = true; break; } if (msg is TranslateMessage) { var translate = (TranslateMessage)msg; Send(translate.player, translate.msg, translate.method); break; } if (msg is MessageList) { IterList(sender, msg); if (gotMessages.Count == 0) { break; } return(gotMessages.Dequeue()); } return(new Message(sender, msg)); case NetIncomingMessageType.StatusChanged: if (Server) { CheckBrokenConnections(); SendPlayersInfo(); } break; default: Log.Info("Got unrecognized message " + message.ReadString()); break; } } return(null); }
// Fires the OnPlayerConnected action, takes the player as a parameter public void InvokePlayerConnected(GameObject player) { Debug.Log("Player connected"); OnPlayerConnected?.Invoke(player); }
public override void OnPlayerEnteredRoom(Player newPlayer) { OnPlayerConnected?.Invoke(newPlayer); }