Esempio n. 1
0
        private new void OnConnected(Socket socket)
        {
            clients.Add(socket, clientId);
            Console.WriteLine("客户端连接");

            //发送断线重连包
            S2C_Join join = new S2C_Join();

            join.Frame     = frame;
            join.YourId    = clientId;
            join.Instances = new List <Instance>();
            foreach (var instance in instances)
            {
                foreach (var item in instance.Value) //该类型下的物体
                {
                    Instance instantiate = new Instance();
                    instantiate.IsLocal = clients[socket] == item.Key;
                    instantiate.TypeId  = instance.Key;
                    instantiate.Id      = item.Key; //物品Id
                    instantiate.X       = item.Value.X;
                    instantiate.Y       = item.Value.Y;
                    //添加
                    join.Instances.Add(instantiate);
                }
            }
            //自增
            clientId++;
            //发送给登陆者
            Send(socket, (ushort)NetworkRole.Server, (ushort)GameCmd.Join, join);
        }
Esempio n. 2
0
        private void JoinCallback(byte[] data)
        {
            S2C_Join join = NetworkSerializer.Deserialize <S2C_Join>(data);

            this.join = true;
            frame     = join.Frame;
            id        = join.YourId;
            if (join.Instances == null) //表示当前没有游戏物体
            {
                return;
            }
            //生成所有游戏物体
            foreach (var instance in join.Instances)
            {
                CreatInstance(instance);
            }
        }