예제 #1
0
    private void OnClientJoined(Guid clientId, string clientName)
    {
        CharacterData character = new CharacterData(
            Guid.NewGuid(),
            clientId,
            UnityEngine.Random.insideUnitCircle * 4f,
            Color.HSVToRGB((totalNumberOfCharactersJoined++ % 7) / 7f, 1f, 1f),
            Instantiate(characterPrefab, transform)
            );

        Debug.Log(string.Format("Spawning a new character {0} because client {1} (with name {2}) joined the server", character.GetId(), clientId, clientName));
        foreach (var otherCharacter in characters.Values)
        {
            karmanServer.Send(clientId, otherCharacter.GetSpawnPacket());
        }
        karmanServer.Broadcast(character.GetSpawnPacket());
        characters.Add(clientId, character);
    }
예제 #2
0
 protected void FixedUpdate()
 {
     if (nextSpawnMoment <= Time.timeSinceLevelLoad)
     {
         nextSpawnMoment += spawnRate;
         GameObject instance = Instantiate(minePrefab, transform);
         MineData   mine     = new MineData(Guid.NewGuid(), transform.position + RandomPointInBounds(spawnBounds), UnityEngine.Random.Range(minMineDuration, maxMineDuration), instance);
         Debug.Log("Spawning a new mine: " + mine.GetId());
         karmanServer.Broadcast(mine.GetSpawnPacket());
     }
 }
예제 #3
0
    private IEnumerator <YieldInstruction> DoScheduledShutdown()
    {
        int shutdownTimeLeft = 5;

        do
        {
            MessagePacket messagePacket = new MessagePacket(string.Format("The server is shutting down in {0} seconds!", shutdownTimeLeft));
            server.Broadcast(messagePacket);
            OnShutdownTimeLeft(shutdownTimeLeft);
            yield return(new WaitForSeconds(1));

            shutdownTimeLeft -= 1;
        } while (shutdownTimeLeft > 0);
        server.Shutdown();
        OnShutdownTimeLeft(0);
    }
예제 #4
0
 private void HandleMutationBy(MutationPacket mutationPacket, Guid requester)
 {
     if (!TryApply(mutationPacket, out Mutation mutation, out MutationResult result))
     {
         if (requester.Equals(Guid.Empty))
         {
             log.Warning($"Mutation[{mutationPacket.GetId()}] failed. Reason: {result.GetFailureReason()}. Details: {mutation.GetType().Name} on fragment[{fragmentKeyFactory.FromBytes(mutationPacket.GetKey()).AsString()}].\nStackTrace: {Environment.StackTrace}");
             SafeInvoker.Invoke(log, OnMutationFailedCallback, mutationPacket.GetId(), result.GetFailureReason());
         }
         else
         {
             server.Send(requester, new MutationFailedPacket(mutationPacket.GetId(), result.GetFailureReason()));
         }
         return;
     }
     server.Broadcast(mutationPacket);
 }