Beispiel #1
0
 //Called when received by server
 public override void Callback(int peerId, AbstractNetworkMessage abstractNetworkMessage)
 {
     if (Tree.IsNetworkServer())
     {
         ClientSendAuthentication clientSendAuthentication = abstractNetworkMessage as ClientSendAuthentication;
         //GD.Print(c);
         Logger LOG = new Logger(this.GetType().Name);
         LOG.Info(System.String.Format("Adding client {0} with name {1} to client list. Sending map data to client", peerId, clientSendAuthentication.SteamID64));
         ClientRepresentation newClient = new ClientRepresentation(peerId, new Vector3(), new Vector3());
         newClient.Name = clientSendAuthentication.SteamID64;
         Server.AddClient(newClient);
         ObjectBroker.Instance.NetworkService.toClient(peerId, new ServerInitialSync("DevWorld/DevWorld.scn"), TransferModeEnum.Reliable);
     }
 }
Beispiel #2
0
        public override void Callback(int peerId, AbstractNetworkMessage abstractNetworkMessage)
        {
            ClientPeerConnectionUpdate clientPeerConnectionUpdate = abstractNetworkMessage as ClientPeerConnectionUpdate;

            if (Tree.IsNetworkServer())
            {
                if (clientPeerConnectionUpdate.Disconnected)
                {
                    ClientRepresentation disconnectedPeer = Server.ConnectedClients[peerId];
                    //disconnect actual peer
                    Server.ENetInstance.DisconnectPeer(peerId, true);
                    foreach (var peer in Server.ConnectedClients)
                    {
                        if (peer.Key != peerId)
                        {
                            ObjectBroker.Instance.NetworkService.toClient(peer.Key, new ClientPeerConnectionUpdate(disconnectedPeer, true));
                        }
                    }
                }
            }
            else
            {
                if (!clientPeerConnectionUpdate.Disconnected)
                {
                    if (Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).HasNode(GD.Str(clientPeerConnectionUpdate.ClientRepresentation.Id)))
                    {
                        return;
                    }

                    PackedScene         peerRepresentationResource = ResourceLoader.Load("res://assets/scenes/Character/Character.tscn") as PackedScene;
                    Godot.KinematicBody peerRepresentation         = peerRepresentationResource.Instance() as Godot.KinematicBody;
                    peerRepresentation.Name = GD.Str(clientPeerConnectionUpdate.ClientRepresentation.Id);
                    peerRepresentation.SetNetworkMaster(clientPeerConnectionUpdate.ClientRepresentation.Id);
                    peerRepresentation.Translation = clientPeerConnectionUpdate.ClientRepresentation.Translation;
                    peerRepresentation.Rotation    = clientPeerConnectionUpdate.ClientRepresentation.Rotation;

                    Node peerName = peerRepresentation.GetNode("Name");
                    ((Label)peerName.GetNode("Viewport/Label")).Text = clientPeerConnectionUpdate.ClientRepresentation.Name;

                    Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).AddChild(peerRepresentation);
                }
                else
                {
                    Node peerNode = Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).GetNode(GD.Str(clientPeerConnectionUpdate.ClientRepresentation.Id));
                    Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).RemoveChild(peerNode);
                    peerNode.QueueFree();
                }
            }
        }
 public void AddClient(ClientRepresentation client)
 {
     ConnectedClients.Add(client.Id, client);
 }
Beispiel #4
0
 public ChatMessage(string Message, ClientRepresentation Sender) : base(NetworkMessageAction.CHAT_MESSAGE)
 {
     this.Message = Message;
     this.Sender  = Sender;
 }
Beispiel #5
0
 public ClientPeerConnectionUpdate(ClientRepresentation clientRepresentation, bool disconnected = false) : base(NetworkMessageAction.CLIENT_PEER_CONNECTION_UPDATE)
 {
     this.ClientRepresentation = clientRepresentation;
     this.Disconnected         = disconnected;
 }