Ejemplo n.º 1
0
        private protected override void ParsePacket(PacketId packetId, object[] args, EndPointId endPointId, SocketInfo socketInfo)
        {
            switch (packetId)
            {
            case PacketId.InitiateDircetInterface:
                InitiateDircetInterfacePacket initiateDircetInterfacePacket = new InitiateDircetInterfacePacket(args.ToList());
                localEndPointId = initiateDircetInterfacePacket.ClientId;
                DircetInterfaceInitiatingPacket initiatingPacket = new DircetInterfaceInitiatingPacket(initiateDircetInterfacePacket.ClientId);
                Send(initiatingPacket, NetworkInterfaceType.UDP);
                hasSynchronized = true;
                break;

            default:
                base.ParsePacket(packetId, args, endPointId, socketInfo);
                break;
            }
        }
Ejemplo n.º 2
0
        private void Synchronize(EndPointId endPointId, EndPoint endPoint)
        {
            lock (clients)
            {
                lock (NetworkIdentity.entities)
                {
                    Console.WriteLine("New player at: " + endPointId);
                    SpawnObjectPacket spawnPacket;
                    clients.Add(endPointId, endPoint);
                    foreach (NetworkIdentity i in NetworkIdentity.entities.Values)
                    {
                        if (i.IsDestroyed)
                        {
                            continue;
                        }

                        spawnPacket = new SpawnObjectPacket(false, GetNetworkClassTypeByName(i.GetType().FullName), i.Id, i.OwnerId, true); //Spawn all existing clients in the remote client
                        SendPacketToAUser(spawnPacket, NetworkInterfaceType.TCP, endPointId);
                    }

                    SyncObjectVars syncObjectVars;
                    foreach (var i in NetworkIdentity.entities.Values)
                    {
                        if (i.IsDestroyed)
                        {
                            continue;
                        }

                        Dictionary <string, string> valuesByFields = GetValuesByFieldsFromObject(i);
                        var args = valuesByFields.Select(k => k.Key + "+" + k.Value).ToArray();
                        syncObjectVars = new SyncObjectVars(false, i.Id, args); //Sync all existing clients vars
                        SendPacketToAUser(syncObjectVars, NetworkInterfaceType.TCP, endPointId);
                    }
                    //Console.WriteLine("Spawn all existing clients");

                    InitiateDircetInterfacePacket initiateDircetInterface = new InitiateDircetInterfacePacket(endPointId);//Initiate dircet interface with the client
                    SendPacketToAUser(initiateDircetInterface, NetworkInterfaceType.TCP, endPointId);
                    //Console.WriteLine("Initiating dircet interface with the client");
                }
            }
        }