Ejemplo n.º 1
0
    public void SendPlayerTurn(int forward, bool stand, Vector3 pos)
    {
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddString("PlayerTurn");
        protocol.AddString(playerid);
        protocol.AddInt(forward);
        protocol.AddBool(stand);

        protocol.AddFloat(pos.x);
        protocol.AddFloat(pos.y);
        protocol.AddFloat(pos.z);

        ProtocolBytes UDPprotocol = new ProtocolBytes();

        UDPprotocol.AddInt(conn_id);

        UDPprotocol.AddString("U");
        UDPprotocol.AddString(playerid);
        UDPprotocol.AddInt(forward);
        UDPprotocol.AddBool(stand);

        UDPprotocol.AddFloat(pos.x);
        UDPprotocol.AddFloat(pos.y);
        UDPprotocol.AddFloat(pos.z);

        UDPSend(UDPprotocol);
        Send(protocol);
    }
Ejemplo n.º 2
0
        public void SendUnitInfo()
        {
            ProtocolBytes proto = new ProtocolBytes();

            proto.AddString("UpdateUnitInfo");
            //位置旋转
            Vector3 pos = transform.Find("MainBody").position;
            Vector3 rot = transform.Find("MainBody").eulerAngles;

            proto.AddFloat(pos.x);
            proto.AddFloat(pos.y);
            proto.AddFloat(pos.z);
            proto.AddFloat(rot.x);
            proto.AddFloat(rot.y);
            proto.AddFloat(rot.z);
            float blood = transform.GetComponent <Damage_Control_CS>().durability;

            proto.AddFloat(blood);

            //炮塔
            float tur_currentAng_out = transform.Find("MainBody").Find("Turret_Base").GetComponent <Turret_Control_CS>().currentAng;
            float tur_targetAng_out  = transform.Find("MainBody").Find("Turret_Base").GetComponent <Turret_Control_CS>().targetAng;

            proto.AddFloat(tur_currentAng_out);
            proto.AddFloat(tur_targetAng_out);
            //炮管
            float canno_current_out = transform.Find("MainBody").Find("Turret_Base").Find("Cannon_Base").GetComponent <Cannon_Control_CS>().currentAng;

            proto.AddFloat(canno_current_out);
            NetMgr.srvConn.Send(proto);
        }
Ejemplo n.º 3
0
 public static void AppendVector3(ProtocolBytes protocol, Vector3 vector)
 {
     if (protocol == null)
     {
         return;
     }
     protocol.AddFloat(vector.x);
     protocol.AddFloat(vector.y);
     protocol.AddFloat(vector.z);
 }
Ejemplo n.º 4
0
    //更新信息
    public void MsgSyncMotionState(Player player, ProtocolBase protoBase)
    {
        //获取数值
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);

        float pos_x = protocol.GetFloat(start, ref start);
        float pos_y = protocol.GetFloat(start, ref start);
        float pos_z = protocol.GetFloat(start, ref start);
        float rot_x = protocol.GetFloat(start, ref start);
        float rot_y = protocol.GetFloat(start, ref start);
        float rot_z = protocol.GetFloat(start, ref start);
        float vel_x = protocol.GetFloat(start, ref start);
        float vel_y = protocol.GetFloat(start, ref start);
        float vel_z = protocol.GetFloat(start, ref start);

        //Scene.instance.UpdateInfo (player.id, x, y, z, score);
        //广播
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("SyncMotionState");
        protocolRet.AddString(player.id);
        protocolRet.AddFloat(pos_x);
        protocolRet.AddFloat(pos_y);
        protocolRet.AddFloat(pos_z);
        protocolRet.AddFloat(rot_x);
        protocolRet.AddFloat(rot_y);
        protocolRet.AddFloat(rot_z);
        protocolRet.AddFloat(vel_x);
        protocolRet.AddFloat(vel_y);
        protocolRet.AddFloat(vel_z);

        ServNet.instance.Broadcast(protocolRet);
    }
Ejemplo n.º 5
0
    public void SendMotionState()
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("SyncMotionState");
        //位置旋转
        Vector3 pos = transform.position;
        Vector3 rot = transform.eulerAngles;
        Vector3 vel = GetComponent <Rigidbody>().velocity;

        //插值:发送方也保留一份发送的状态
        lastMotionState.position     = pos;
        lastMotionState.rotation     = rot;
        lastMotionState.velocity     = vel;
        lastMotionState.lastSyncTime = Time.time;

        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        proto.AddFloat(pos.z);
        proto.AddFloat(rot.x);
        proto.AddFloat(rot.y);
        proto.AddFloat(rot.z);
        proto.AddFloat(vel.x);
        proto.AddFloat(vel.y);
        proto.AddFloat(vel.z);

        NetMgr.srvConn.Send(proto);
    }
Ejemplo n.º 6
0
    // 发送位置信息
    void Send()
    {
        // 消息
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("UpdateInfo");
        proto.AddFloat(this.transform.position.x);
        proto.AddFloat(this.transform.position.y);
        proto.AddFloat(this.transform.position.z);
        NetMgr.srvConn.Send(proto);
    }
Ejemplo n.º 7
0
 public static void AppendQuaternion(ProtocolBytes protocol, Quaternion quaternion)
 {
     if (protocol == null)
     {
         return;
     }
     protocol.AddFloat(quaternion.x);
     protocol.AddFloat(quaternion.y);
     protocol.AddFloat(quaternion.z);
     protocol.AddFloat(quaternion.w);
 }
Ejemplo n.º 8
0
    public void SendBlockGenerate(string net_id, float x, float y, int ID)
    {
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddString("BlockGenerate");
        protocol.AddString(net_id);
        protocol.AddFloat(x);
        protocol.AddFloat(y);
        protocol.AddInt(ID);

        Send(protocol);
    }
Ejemplo n.º 9
0
    //public void PlayerCtrl()
    //{
    //    if (ctrlType != CtrlType.human)
    //    {
    //        return;
    //    }


    //    if (Time.time - lastSendInfoTime > 0.2f)
    //    {
    //        SendUnitInfo();
    //        lastSendInfoTime = Time.time;
    //    }
    //}

    //发送位置信息
    public void SendUnitInfo()
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("UpdateInfo");
        //位置
        Vector3 pos = transform.position;

        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        NetMgr.srvConn.Send(proto);
    }
Ejemplo n.º 10
0
    void SendPos()
    {
        GameObject player = players[playerID];
        Vector3    pos    = player.transform.position;
        //消息
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("UpdateInfo");
        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        NetMgr.srvConn.Send(proto);
    }
Ejemplo n.º 11
0
    //发送位置
    public void SendPos()
    {
        GameObject player = players[playerID];
        Vector3    pos    = player.transform.position;
        //消息
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("UpdateInfo");
        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        proto.AddFloat(pos.z);
        connectToTheServer.Send(proto);
    }
Ejemplo n.º 12
0
    void SendRotate()
    {
        GameObject    player   = players[playerId];
        Quaternion    rot      = player.transform.rotation;
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddString("UpdateRot");
        protocol.AddFloat(rot.x);
        protocol.AddFloat(rot.y);
        protocol.AddFloat(rot.z);
        protocol.AddFloat(rot.w);
        NetMgr.srvConn.Send(protocol);
    }
Ejemplo n.º 13
0
    private void UDPReceiveCb(IAsyncResult ar)
    {
        int count = UDPsocket.EndReceiveFrom(ar, ref UDPRemote);

        Array.Copy(UDPreadBuff, UDPlenBytes, sizeof(Int32));
        int msgLength = BitConverter.ToInt32(UDPlenBytes, 0);

        ProtocolBase  protocolBase = proto.Decode(UDPreadBuff, sizeof(Int32), msgLength);
        ProtocolBytes protocol     = (ProtocolBytes)protocolBase;
        int           start        = 0;
        int           conn_id      = protocol.GetInt(start, ref start);

        string protoName = protocol.GetString(start, ref start);

        if (protoName == "A")
        {
            conns[conn_id].UDPRemote = UDPRemote;
            UDPsocket.BeginReceiveFrom(UDPreadBuff, 0, BUFFER_SIZE, SocketFlags.None, ref TempRemote, UDPReceiveCb, UDPreadBuff);
            return;
        }
        else if (protoName != "U")
        {
            UDPsocket.BeginReceiveFrom(UDPreadBuff, 0, BUFFER_SIZE, SocketFlags.None, ref TempRemote, UDPReceiveCb, UDPreadBuff);
            return;
        }

        int    DataID = protocol.GetInt(start, ref start);
        string id     = protocol.GetString(start, ref start);

        float x = protocol.Getfloat(start, ref start);
        float y = protocol.Getfloat(start, ref start);
        float z = protocol.Getfloat(start, ref start);

        ProtocolBytes Recombine = new ProtocolBytes();

        Recombine.AddString(protoName);
        Recombine.AddInt(DataID);

        Recombine.AddString(id);

        Recombine.AddFloat(x);
        Recombine.AddFloat(y);
        Recombine.AddFloat(z);

        HandleMsg(conns[conn_id], Recombine);

        Array.Copy(UDPreadBuff, sizeof(Int32) + msgLength, UDPreadBuff, 0, count);

        UDPsocket.BeginReceiveFrom(UDPreadBuff, 0, BUFFER_SIZE, SocketFlags.None, ref TempRemote, UDPReceiveCb, UDPreadBuff);
    }
Ejemplo n.º 14
0
    public void SendUnitInfo()
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("UpdateUnitInfo");
        //位置旋转
        Vector3 pos = transform.position;
        Vector3 rot = transform.eulerAngles;

        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        proto.AddFloat(pos.z);
        proto.AddFloat(rot.x);
        proto.AddFloat(rot.y);
        proto.AddFloat(rot.z);
        //炮塔
        float angleY = turretRotTarget;

        proto.AddFloat(angleY);
        //炮管
        float angleX = turretRollTarget;

        proto.AddFloat(angleX);
        NetMgr.srvConn.Send(proto);
    }
Ejemplo n.º 15
0
    //发送位置
    public void SendInfo()
    {
        GameObject player = players[playerID];
        Vector3    pos    = player.transform.position;
        //消息
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("UpdateInfo");
        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        proto.AddFloat(pos.z);
        proto.AddFloat(player.transform.localScale.x);            //角色朝向
        proto.AddInt(player.GetComponent <Character>().animInfo); //动画状态
        NetMgr.srvConn.Send(proto);
    }
Ejemplo n.º 16
0
    public ProtocolBytes GetUnitData(int DataID, string protoName, string id, Vector3 pos)
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString(protoName);
        proto.AddInt(DataID);

        proto.AddString(id);

        proto.AddFloat(pos.x);
        proto.AddFloat(pos.y);
        proto.AddFloat(pos.z);

        return(proto);
    }
Ejemplo n.º 17
0
    //伤害处理, 同时也做胜负判断
    //协议参数: string enemyName, float damage
    //f协议: string player.id, string enemy.id, float damage
    public void MsgHit(Player player, ProtocolBase protoBase)
    {
        //解析协议
        int           start    = 0;
        ProtocolBytes protocol = (ProtocolBytes)protoBase;
        float         damage   = protocol.GetFloat(start, ref start);

        //更多作弊校验 略
        //获取房间
        if (player.tempData.status != PlayerTempData.Status.Fight)
        {
            return;
        }
        Room room = player.tempData.room;

        Logger.Default.Trace("MsgHit " + " damage:" + damage);
        //广播
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("Hit");
        protocolRet.AddString(player.id);
        //protocolRet.AddString (enemy.id);
        protocolRet.AddFloat(damage);
        room.Broadcast(protocolRet);
        //胜负判断
        //room.UpdateWin ();   //下一节实现
    }
Ejemplo n.º 18
0
    public void SendPlayerList(Player player)
    {
        int           count    = list.Count;
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddString("GetList");
        protocol.AddInt(count);
        for (int i = 0; i < count; i++)
        {
            ScenePlayer p = list[i];
            protocol.AddString(p.id);
            protocol.AddFloat(p.x);
            protocol.AddFloat(p.y);
            protocol.AddFloat(p.z);
        }
        player.Send(protocol);
    }
Ejemplo n.º 19
0
    public void SendShoot(string id, int isPlayer, int forward, Vector3 pos, int addforce)
    {
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddString("Shoot");
        protocol.AddString(id);
        protocol.AddInt(isPlayer);

        protocol.AddInt(forward);

        protocol.AddFloat(pos.x);
        protocol.AddFloat(pos.y);
        protocol.AddFloat(pos.z);

        protocol.AddInt(addforce);

        Send(protocol);
    }
Ejemplo n.º 20
0
    public void SendHit(string id, float damage)
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString("Hit");
        proto.AddString(id);
        proto.AddFloat(damage);
        NetMgr.srvConn.Send(proto);
    }
    //伤害处理, 同时也做胜负判断
    //协议参数: string enemyName, float damage
    //f协议: string player.id, string enemy.id, float damage
    public void MsgHit(Player player, ProtocolBase protoBase)
    {
        //解析协议
        int           start    = 0;
        ProtocolBytes protocol = (ProtocolBytes)protoBase;
        // string protoName = protocol.GetString (start, ref start);
        // string enemyName = protocol.GetString (start, ref start);
        float damage = protocol.GetFloat(start, ref start);

        //作弊校验

        /*
         *      long lastShootTime = player.tempData.lastShootTime;
         *      if (Sys.GetTimeStamp () - lastShootTime < 1)
         *      {
         *              Logger.Default.Info ("MsgHit开炮作弊 " + player.id);
         *              return;
         *      }
         *      player.tempData.lastShootTime = Sys.GetTimeStamp();
         */
        //更多作弊校验 略
        //获取房间
        if (player.tempData.status != PlayerTempData.Status.Fight)
        {
            return;
        }
        Room room = player.tempData.room;

        //扣除生命值

        /*
         *      if (!room.list.ContainsKey (enemyName))
         *      {
         *              Logger.Default.Info ("MsgHit not Contains enemy " + enemyName);
         *              return;
         *      }
         *      Player enemy = room.list[enemyName];
         *      if (enemy == null)
         *              return;
         *      if (enemy.tempData.hp <= 0)
         *              return;
         *      enemy.tempData.hp -= damage;
         */
        //Logger.Default.Info("MsgHit " + enemyName + "  hp:" + enemy.tempData.hp + " damage:" + damage);
        Logger.Default.Trace("MsgHit " + " damage:" + damage);
        //广播
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("Hit");
        protocolRet.AddString(player.id);
        //protocolRet.AddString (enemy.id);
        protocolRet.AddFloat(damage);
        room.Broadcast(protocolRet);
        //胜负判断
        //room.UpdateWin ();   //下一节实现
    }
Ejemplo n.º 22
0
    /// <summary>
    /// 获取 Ping 协议消息
    /// </summary>
    /// <returns></returns>
    public ProtocolBase GetPingProtocol()
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString(Constant.Ping);
        // 添加当前时间(游戏开始到现在的时间)
        proto.AddFloat(Time.time);

        return(proto);
    }
Ejemplo n.º 23
0
    /// <summary>
    /// 将所有地形的相同基础数据保存为头文件
    /// </summary>
    /// <param name="path">路径</param>
    private void SaveTDHead(string path)
    {
        Terrain terrain = Terrain.activeTerrain;
        TDHead  tDHead  = new TDHead
        {
            terrainSize         = terrain.terrainData.size,
            ResolutionSize      = terrain.terrainData.detailResolution,
            heightmapPixelError = terrain.heightmapPixelError,
            basemapDistance     = terrain.basemapDistance,
            drawHeightmap       = terrain.drawHeightmap,
        };
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddVector3(tDHead.terrainSize);
        protocol.AddInt32(tDHead.ResolutionSize);
        protocol.AddFloat(tDHead.heightmapPixelError);
        protocol.AddFloat(tDHead.basemapDistance);
        protocol.AddBoolen(tDHead.drawHeightmap);
        File.WriteAllBytes(path + "/TerrainData.tdHead", protocol.Encode());
    }
Ejemplo n.º 24
0
    public void MsgUpdateInfo(Player player, ProtocolBase protoBase)
    {
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);
        float         x         = protocol.GetFloat(start, ref start);
        float         y         = protocol.GetFloat(start, ref start);
        float         z         = protocol.GetFloat(start, ref start);

        Scene.instance.UpdateInfo(player.id, x, y, z);

        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("UpdateInfo");
        protocolRet.AddString("Player.id");
        protocolRet.AddFloat(x);
        protocolRet.AddFloat(y);
        protocolRet.AddFloat(z);
        ServNet.instance.Broadcast(protocolRet);
    }
Ejemplo n.º 25
0
        public void GetPos(Conn conn, ProtocolBase protocol)
        {
            ProtocolBytes p   = protocol as ProtocolBytes;
            Pos           pos = dataMgr.GetPlayerPos(conn.player.ID);
            ProtocolBytes result;

            if (pos != null)
            {
                result = new ProtocolBytes(requestCode, EActionCode.GetPos, EReturnCode.Success);
                result.AddInt(pos.MapNum);
                result.AddFloat(pos.X);
                result.AddFloat(pos.Y);
                result.AddFloat(pos.Z);
            }
            else
            {
                result = new ProtocolBytes(requestCode, EActionCode.GetPos, EReturnCode.Failed);
            }
            Send(conn, result);
        }
Ejemplo n.º 26
0
    /// <summary>
    /// 向 Server 发送飞船的位置和转向信息
    /// </summary>
    private void SendShipInfoToServer()
    {
        // 组装协议
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString(Constant.UpdateShipInfo);

        // 位置
        Vector2 mov = _deltaMovement;
        // 旋转
        Vector2 rot = _deltaRotation;

        proto.AddFloat(mov.x);
        proto.AddFloat(mov.y);
        proto.AddFloat(rot.x);
        proto.AddFloat(rot.y);

        // 向 Server 发送消息
        NetMgr.Instance.srvConn.Send(proto);
    }
Ejemplo n.º 27
0
    //伤害处理
    public void MsgHit(Player player, ProtocolBase protoBase)
    {
        //解析协议
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);
        string        enemyName = protocol.GetString(start, ref start);
        float         damage    = protocol.GetFloat(start, ref start);
        //作弊校验
        long lastShootTime = player.tempData.lastShootTime;

        if (Sys.GetTimeStamp() - lastShootTime < 1)
        {
            Console.WriteLine("MsgHit开炮作弊 " + player.id);
            return;
        }
        player.tempData.lastShootTime = Sys.GetTimeStamp();
        //更多作弊校验 略
        //获取房间
        if (player.tempData.status != PlayerTempData.Status.Fight)
        {
            return;
        }
        Room room = player.tempData.room;

        //扣除生命值
        if (!room.list.ContainsKey(enemyName))
        {
            Console.WriteLine("MsgHit not Contains enemy " + enemyName);
            return;
        }
        Player enemy = room.list[enemyName];

        if (enemy == null)
        {
            return;
        }
        if (enemy.tempData.hp <= 0)
        {
            return;
        }
        enemy.tempData.hp -= damage;
        Console.WriteLine("MsgHit " + enemyName + "  hp:" + enemy.tempData.hp + " damage:" + damage);
        //广播
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("Hit");
        protocolRet.AddString(player.id);
        protocolRet.AddString(enemy.id);
        protocolRet.AddFloat(damage);
        room.Broadcast(protocolRet);
        //胜负判断
        room.UpdateWin();
    }
Ejemplo n.º 28
0
        public void SendBloodInfo()
        {
            ProtocolBytes proto = new ProtocolBytes();

            proto.AddString("Blood");
            //durability
            float blood = transform.GetComponent <Damage_Control_CS>().durability;

            proto.AddFloat(blood);

            NetMgr.srvConn.Send(proto);
        }
Ejemplo n.º 29
0
    /// <summary>
    /// 发射炮弹协议
    /// </summary>
    /// <param name="player">Player.</param>
    /// <param name="protoBase">Proto base.</param>
    public void MsgShooting(Player player, ProtocolBase protoBase)
    {
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        int           start     = 0;
        string        protoName = protocol.GetString(start, ref start);
        float         posX      = protocol.GetFloat(start, ref start);
        float         posY      = protocol.GetFloat(start, ref start);
        float         posZ      = protocol.GetFloat(start, ref start);
        float         rotX      = protocol.GetFloat(start, ref start);
        float         rotY      = protocol.GetFloat(start, ref start);
        float         rotZ      = protocol.GetFloat(start, ref start);

        if (player.tempData.status != PlayerTempData.Status.Fight)
        {
            return;
        }
        Room          room     = player.tempData.room;
        ProtocolBytes protoRet = new ProtocolBytes();

        protoRet.AddString("Shooting");
        protoRet.AddString(player.id);
        protoRet.AddFloat(posX);
        protoRet.AddFloat(posY);
        protoRet.AddFloat(posZ);
        protoRet.AddFloat(rotX);
        protoRet.AddFloat(rotY);
        protoRet.AddFloat(rotZ);
        room.Broadcast(protoRet);
    }
Ejemplo n.º 30
0
    public ProtocolBytes GetInfoProto(string protoName)
    {
        ProtocolBytes proto = new ProtocolBytes();

        proto.AddString(protoName);
        proto.AddString(id); //如果是玩家,id是房间内id,否则是unity创建id

        proto.AddString(prefabname);
        proto.AddFloat(x);
        proto.AddFloat(y);
        proto.AddFloat(z);

        proto.AddInt(health);
        proto.AddInt(damage);
        proto.AddFloat(speed);

        proto.AddInt(clip);
        proto.AddInt(addforce);
        proto.AddFloat(calmtime);

        proto.AddString(boltname);
        proto.AddString(dropname);

        proto.AddInt(type);
        proto.AddInt(value);
        proto.AddFloat(probability);
        proto.AddInt(camp);

        return(proto);
    }