WriteFloat() public method

public WriteFloat ( float v ) : void
v float
return void
Beispiel #1
0
 /// <summary>
 /// Sends already connected clients to the connecting one
 /// </summary>
 /// <param name="id"></param>
 /// <param name="p"></param>
 static void NotifyMainPlayerOfAlreadyConnected(int id)         // sends already connected to players current player
 {
     for (int i = 0; i < 20; i++)
     {
         if (Globals.clients[i] != null && Globals.clients[i].Connected)
         {
             if (i != id)
             {
                 Console.WriteLine(i);
                 ByteBuffer buffer = new ByteBuffer();
                 buffer.WriteInt((int)Enums.AllEnums.SSendingAlreadyConnectedToMain);
                 buffer.WriteString(Globals.dicPlayers[i].uName);
                 buffer.WriteString(Globals.dicPlayers[i].cName);
                 buffer.WriteInt(Globals.dicPlayers[i].head);
                 buffer.WriteInt(Globals.dicPlayers[i].body);
                 buffer.WriteInt(Globals.dicPlayers[i].cloths);
                 buffer.WriteFloat(Globals.dicPlayers[i].cX);
                 buffer.WriteFloat(Globals.dicPlayers[i].cY);
                 buffer.WriteFloat(Globals.dicPlayers[i].cZ);
                 Thread.Sleep(1000);                         //If the thread doesnt sleep, the packet is not sent
                 //Console.WriteLine(buffer.ToArray().Length+" to "+id);
                 try
                 {
                     Globals.clients[id].GetStream().Write(buffer.ToArray(), 0, buffer.ToArray().Length);
                 }
                 catch (Exception) { continue; }
             }
         }
     }
 }
Beispiel #2
0
        public void ShouldWriteFloat()
        {
            byteBuffer.WriteFloat(inputFloat);
            byte[] floatByteLength = new byte[sizeof(float)];
            int    bufferLength    = byteBuffer.Length();

            Assert.Equal(bufferLength, floatByteLength.Length);
        }
Beispiel #3
0
    /// <summary>
    /// Sends GPS location to the server.
    /// </summary>
    /// <param name="lat"></param>
    /// <param name="lon"></param>
    public void SendGPS(float lat, float lon)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteInteger(5);
        buffer.WriteFloat(lat);
        buffer.WriteFloat(lon);
        SendDataToServer(buffer.ToArray());
        buffer = null;
    }
Beispiel #4
0
    void sendMsg(int id)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteInt(id);
        buffer.WriteFloat(21.4f);
        buffer.WriteFloat(18.6f);
        buffer.WriteFloat(0.43387f);

        client.Send(buffer.ToBytes());
    }
Beispiel #5
0
	public void SendMovement(int id, float x, float y, float z)
	{
		ByteBuffer buffer = new ByteBuffer();
		buffer.WriteInt((int)Assets.Scripts.Enums.AllEnums.SSyncingPlayerMovement);
		buffer.WriteInt(id);
		buffer.WriteFloat(x);
		buffer.WriteFloat(y);
		buffer.WriteFloat(z);
		myStream.Write(buffer.ToArray(), 0, buffer.ToArray().Length);
		myStream.Flush();
	}
    public static void SendGameRules(int connectionID)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.GameRules);
        buffer.WriteFloat(Constants.GAMERULES.MAX_PLAYER_HEALTH);
        buffer.WriteFloat(Constants.GAMERULES.PLAYER_STARTING_HEALTH);

        SendDataTo(connectionID, buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #7
0
    /// <summary>
    /// Uses the ByteBuffer class to serialise the enemy attributes into a byte array.
    /// </summary>
    /// <returns>Byte array containing enemy data.</returns>
    public byte[] Serialise()
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteInteger(id);
        buffer.WriteString(name);
        buffer.WriteFloat(lat);
        buffer.WriteFloat(lon);

        return(buffer.ToArray());
    }
    public static void SendPlayerStats(int connectionID, float health, float hunger, float thirst)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.PlayerStats);
        buffer.WriteInteger(connectionID);

        buffer.WriteFloat(health);
        buffer.WriteFloat(hunger);
        buffer.WriteFloat(thirst);

        SendDataToAll(buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #9
0
            public static byte[] Write(AccessRect access)
            {
                ByteBuffer bfs = new ByteBuffer();

                bfs.WriteFloat(access.Rect.x);
                bfs.WriteFloat(access.Rect.y);
                bfs.WriteFloat(access.Rect.width);
                bfs.WriteFloat(access.Rect.height);
                bfs.WriteByte((byte)access.State);
                bfs.WriteBool(access.Enable);
                bfs.WriteByte((byte)access.Type);
                bfs.WriteInt32(access.HashID);
                return(bfs.Getbuffer());
            }
Beispiel #10
0
    public static void SendSyncPosition(int syncObjID, NetworkObjectType type, Vector3 pos)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.SyncPosition);
        buffer.WriteLong((long)type);
        buffer.WriteInteger(syncObjID);

        buffer.WriteFloat(pos.x);
        buffer.WriteFloat(pos.y);
        buffer.WriteFloat(pos.z);

        SendData(buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #11
0
 protected override void writeVectorToBuffer(ByteBuffer buffer)
 {
     foreach (float val in values)
     {
         buffer.WriteFloat(val);
     }
 }
Beispiel #12
0
        /// <summary>
        /// 将配置数据按照值对的形式写入二进制数据
        /// </summary>
        /// <param name="byteBuffer"></param>
        /// <param name="typeValue"></param>
        /// <param name="field"></param>
        /// <param name="propName"></param>
        private static void WriteField(ref ByteBuffer byteBuffer, string typeValue, string field, string propName)
        {
            switch (typeValue)
            {
            case "int32":
                Debug.Log("Write in int32, " + propName + " = " + int.Parse(field));
                byteBuffer.WriteInt(int.Parse(field));
                break;

            case "string":
                Debug.Log("Write in string, " + propName + " = " + field);
                byteBuffer.WriteString(field);
                break;

            case "float":
                Debug.Log("Write in float, " + propName + " = " + float.Parse(field));
                byteBuffer.WriteFloat(float.Parse(field));
                break;

            case "bool":
                int value = field == "True" || field == "TRUE" ? 1 : 0;
                Debug.Log("Write in bool, field is " + field);
                Debug.Log("Write in bool, " + propName + " = " + value);
                byteBuffer.WriteInt(value);
                break;
            }
        }
Beispiel #13
0
    void WriteData(string type, string data, uint length = 0)
    {
        switch (type)
        {
        case "int":
            NowBuffer.WriteInt(int.Parse(data));
            break;

        case "uint":
            NowBuffer.WriteUInt(uint.Parse(data));
            break;

        case "string":
            NowBuffer.WriteString(data, length);
            break;

        case "byte":
            NowBuffer.WriteByte(byte.Parse(data));
            break;

        case "ushort":
            NowBuffer.WriteUShort(ushort.Parse(data));
            break;

        case "short":
            NowBuffer.WriteShort(short.Parse(data));
            break;

        case "float":
            NowBuffer.WriteFloat(float.Parse(data));
            break;
        }
    }
Beispiel #14
0
    public static void SendSyncRotation(int syncObjID, NetworkObjectType type, Quaternion rot)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.SyncRotation);
        buffer.WriteLong((long)type);
        buffer.WriteInteger(syncObjID);

        buffer.WriteFloat(rot.x);
        buffer.WriteFloat(rot.y);
        buffer.WriteFloat(rot.z);
        buffer.WriteFloat(rot.w);

        SendData(buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #15
0
    void sendMsgFloat(int id, float msg)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteInt(id);
        buffer.WriteFloat(msg);
        client.Send(buffer.ToBytes());
    }
Beispiel #16
0
    public static byte[] CreateInBinary(NodeGraph data)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteString(data.Name);
        buffer.WriteByte((byte)data.Type);
        buffer.WriteString(data.ScriptName);
        buffer.WriteInt32(data.Weight);
        buffer.WriteFloat(data.NodeRect.x);
        buffer.WriteFloat(data.NodeRect.y);
        buffer.WriteInt32(data.Nodes.Count);
        for (int i = 0; i < data.Nodes.Count; ++i)
        {
            buffer.WriteBytes(CreateInBinary(data.Nodes[i]));
        }
        return(buffer.Getbuffer());
    }
Beispiel #17
0
        public static ByteBuffer Write(VisualNode node)
        {
            ByteBuffer bfs = new ByteBuffer();

            bfs.WriteString(node.Title);
            bfs.WriteFloat(node.rect.x);
            bfs.WriteFloat(node.rect.y);
            bfs.WriteFloat(node.rect.width);
            bfs.WriteFloat(node.rect.height);
            bfs.WriteByte((byte)node.fields.Count);
            for (int i = 0; i < node.fields.Count; ++i)
            {
                bfs.WriteBytes(FieldNode.Write(node.fields[i]));
            }
            bfs.WriteBytes(FlowNode.Write(node.currentFlow));
            return(bfs);
        }
Beispiel #18
0
    public static void SendSyncPosition(int connectionID, long type, int syncObjID, float x, float y, float z)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.SyncPosition);
        buffer.WriteLong(type);
        buffer.WriteInteger(syncObjID);

        buffer.WriteFloat(x);
        buffer.WriteFloat(y);
        buffer.WriteFloat(z);

        _data.UpdateObject(syncObjID, new Vector3(x, y, z));

        SendDataToAllBut(connectionID, buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #19
0
    public static void SendNetSpawnRequest(int connectionID, string slug, float x, float y, float z, float rotX, float rotY, float rotZ, float rotW)
    {
        _data.RegisterObject(slug, x, y, z, rotX, rotY, rotZ, rotW);

        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.NetSpawn);

        buffer.WriteInteger(_data.Index);

        buffer.WriteString(slug);

        buffer.WriteFloat(x);
        buffer.WriteFloat(y);
        buffer.WriteFloat(z);

        buffer.WriteFloat(rotX);
        buffer.WriteFloat(rotY);
        buffer.WriteFloat(rotZ);
        buffer.WriteFloat(rotW);

        Console.WriteLine(_data.Index);

        SendDataToAll(buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #20
0
    public static void SendSpawnedObjects(int connectionID)
    {
        ByteBuffer buffer = new ByteBuffer();

        for (int i = 0; i < _data.Index; i++)
        {
            SpawnedPrefab sp = _data.spawnedPrefabs[i];
            buffer.WriteLong((long)PacketType.NetSpawn);

            buffer.WriteInteger(sp.assignedID);

            buffer.WriteString(sp.slug);

            buffer.WriteFloat(sp.transform.position.x);
            buffer.WriteFloat(sp.transform.position.y);
            buffer.WriteFloat(sp.transform.position.z);

            buffer.WriteFloat(sp.transform.rotation.x);
            buffer.WriteFloat(sp.transform.rotation.y);
            buffer.WriteFloat(sp.transform.rotation.z);
            buffer.WriteFloat(sp.transform.rotation.w);

            SendDataTo(connectionID, buffer.ToArray());
            buffer.Dispose();
        }
    }
Beispiel #21
0
    static int WriteFloat(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        ByteBuffer obj  = (ByteBuffer)LuaScriptMgr.GetNetObjectSelf(L, 1, "ByteBuffer");
        float      arg0 = (float)LuaScriptMgr.GetNumber(L, 2);

        obj.WriteFloat(arg0);
        return(0);
    }
Beispiel #22
0
        void WriteArrayValues(object entry, FieldInfo fieldInfo, ByteBuffer buffer)
        {
            var type  = fieldInfo.FieldType.GetElementType();
            var array = (Array)fieldInfo.GetValue(entry);

            for (var i = 0; i < array.Length; ++i)
            {
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Boolean:
                    buffer.WriteUInt8((byte)((bool)array.GetValue(i) ? 1 : 0));
                    break;

                case TypeCode.SByte:
                    buffer.WriteInt8((sbyte)array.GetValue(i));
                    break;

                case TypeCode.Byte:
                    buffer.WriteUInt8((byte)array.GetValue(i));
                    break;

                case TypeCode.Int16:
                    buffer.WriteInt16((short)array.GetValue(i));
                    break;

                case TypeCode.UInt16:
                    buffer.WriteUInt16((ushort)array.GetValue(i));
                    break;

                case TypeCode.Int32:
                    buffer.WriteInt32((int)array.GetValue(i));
                    break;

                case TypeCode.UInt32:
                    buffer.WriteUInt32((uint)array.GetValue(i));
                    break;

                case TypeCode.Int64:
                    buffer.WriteInt64((long)array.GetValue(i));
                    break;

                case TypeCode.UInt64:
                    buffer.WriteUInt64((ulong)array.GetValue(i));
                    break;

                case TypeCode.Single:
                    buffer.WriteFloat((float)array.GetValue(i));
                    break;

                case TypeCode.String:
                    var str = (string)array.GetValue(i);
                    buffer.WriteCString(str);
                    break;
                }
            }
        }
Beispiel #23
0
        public override byte[] Serialize()
        {
            ByteBuffer buffer = new ByteBuffer(Size);

            buffer.WriteByte(TypeID);
            buffer.WriteShort((short)Name.Length);
            buffer.WriteString(Name, Encoding.ASCII, Name.Length);
            buffer.WriteFloat((float)Value);
            return(buffer.Data);
        }
Beispiel #24
0
 public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out)
 {
     targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement);
     for (int i = 0; i < targetNumElement; ++i)
     {
         @out.WriteFloat(values[indexStart + i]);
     }
     numElement = targetNumElement;
     partial    = 0;
     return(targetNumElement * 4);
 }
Beispiel #25
0
    public static void SendDamage(int connectionID, float damage)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.Damage);
        buffer.WriteInteger(connectionID);
        buffer.WriteFloat(damage);

        SendDataToAll(buffer.ToArray());
        buffer.Dispose();
    }
    public static void SendTakeDamages(int targetID, float damages)
    {
        // methodID, fromID, to, damages
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteInteger((int)Packets.CTakeDamages);
        buffer.WriteInteger(Client.connectionID);
        buffer.WriteString($"to {targetID}");
        buffer.WriteFloat(damages);
        SendData(buffer.ToArray());
        buffer.Dispose();
    }
Beispiel #27
0
        public static void Send_WithdrawFunds(float sum, string requisites)
        {
            ByteBuffer buffer = new ByteBuffer();

            //Write packet id
            buffer.WriteLong((long)ClientPacketId.WithdrawFunds);

            // withdraw sum
            buffer.WriteFloat(sum);
            buffer.WriteString(requisites);

            SendDataToServer(buffer.ToArray());
        }
Beispiel #28
0
    void sendMsgFloat(int id, float msg)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteInt(id);
        buffer.WriteFloat(msg);

        for (int i = 0; i < socketList.Count; i++)
        {
            int msgLength = socketList[i].Send(buffer.ToBytes());
            Debug.Log(TAG + "Send msg length: " + msgLength);
        }
    }
Beispiel #29
0
 static int WriteFloat(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         ByteBuffer obj  = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer));
         float      arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
         obj.WriteFloat(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #30
0
    public static byte[] PlayerData(int connectionID)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteLong((long)PacketType.PlayerData);
        buffer.WriteInteger(connectionID);

        Player p = Clients[connectionID].player;

        buffer.WriteFloat(p.Transform.position.x);
        buffer.WriteFloat(p.Transform.position.y);
        buffer.WriteFloat(p.Transform.position.z);

        buffer.WriteFloat(p.Transform.rotation.x);
        buffer.WriteFloat(p.Transform.rotation.y);
        buffer.WriteFloat(p.Transform.rotation.z);
        buffer.WriteFloat(p.Transform.rotation.w);

        buffer.WriteFloat(p.Health);
        buffer.WriteFloat(p.Hunger);
        buffer.WriteFloat(p.Thirst);

        return(buffer.ToArray());
    }