public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var name = msg.ReadString(); if (name.Length > 0) { var command = new KickPlayer() { Player = Authentication.Players[connection.Index] }; command.Kick(name); } }
public override void Decode(ByteBuffer bb) { Term = bb.ReadLong(); LeaderId = bb.ReadString(); PrevLogIndex = bb.ReadLong(); PrevLogTerm = bb.ReadLong(); Entries.Clear(); for (int c = bb.ReadInt(); c > 0; --c) { Entries.Add(bb.ReadBinary()); } LeaderCommit = bb.ReadLong(); }
private static void HandleInstantiate(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); int fromID = buffer.ReadInteger(); buffer.ReadString(); string stringPos = buffer.ReadString(); bool calledForResponse = buffer.ReadBool(); buffer.Dispose(); string[] components = stringPos.Split(';'); Vector3 pos = new Vector3(float.Parse(components[0]), float.Parse(components[1]), float.Parse(components[2])); NetworkManager.instance.CreateNetworkPlayer(fromID, pos); if (!calledForResponse) { DataSender.SendInstantiate(NetworkManager.GetLocalPlayer().transform.position, $"to {fromID}", true); } }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var text = msg.ReadString().Trim(); if (text.Length > 0) { var message = new Message() { Player = Authentication.Players[connection.Index] }; message.Emote(text); } }
public static void HandleWelcomeMsg(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); int packetID = buffer.ReadInt(); string msg = buffer.ReadString(); buffer.Dispose(); DataSender.SendHelloServer(); Debug.Log(msg); }
private static void HandleOtherDie(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); int fromID = buffer.ReadInteger(); buffer.ReadString(); int killerID = buffer.ReadInteger(); buffer.Dispose(); NetworkManager.DestroyGameObject(NetworkManager.GetNetworkPlayer(fromID)); }
public void HandleRecevieMsg(byte[] bytes, PlazaSession client) { ByteBuffer read = new ByteBuffer(bytes); string readMsg = read.ReadString(); string msg = "收到[" + client.GetAddress() + "]发来消息内容:" + readMsg; sessionCode.MainCmdId = 0; sessionCode.SubCmdId = 1002; ByteBuffer buff = new ByteBuffer(); buff.WriteString(msg); sessionCode.SetBytes(buff.ToBytes()); byte[] byteCode = serial.Encode(sessionCode); SeverNet.instance.Broadcast(client, byteCode); }
/// <summary> /// Deserialises the byte array and converts the data into enemy object. /// </summary> /// <param name="data">Byte array sent from the server.</param> private void Desserialise(byte[] data) { enemies = new List <Enemy>(); ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); int packetNum = buffer.ReadInteger(); //Identifies the enemy to be created. int count = buffer.ReadInteger(); for (int i = 0; i < count; i++) { int id = buffer.ReadInteger(); switch (id) { case 1: Wizard wiz = new Wizard(); wiz.id = id; wiz.name = buffer.ReadString(); wiz.lat = buffer.ReadFloat(); wiz.lon = buffer.ReadFloat(); enemies.Add(wiz); break; case 2: Skeleton skel = new Skeleton(); skel.id = id; skel.name = buffer.ReadString(); skel.lat = buffer.ReadFloat(); skel.lon = buffer.ReadFloat(); enemies.Add(skel); break; } } }
public void HandleRecevieMsg(byte[] bytes) { ByteBuffer read = new ByteBuffer(bytes); string readMsg = read.ReadString(); Console.WriteLine(readMsg); SocketClient.instance.onSendMsg(); //string msg = "收到[" + client.GetAddress() + "]发来消息内容:" + readMsg; //sessionCode.MainCmdId = 0; //sessionCode.SubCmdId = 1002; //ByteBuffer buff = new ByteBuffer(); //buff.WriteString(msg); //sessionCode.SetBytes(buff.ToBytes()); //byte[] byteCode = serial.Encode(sessionCode); }
static int ReadString(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); ByteBuffer obj = (ByteBuffer)ToLua.CheckObject <ByteBuffer>(L, 1); string o = obj.ReadString(); LuaDLL.lua_pushstring(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 二进制消息 /// </summary> void OnBinaryMessage(ClientSession session, ByteBuffer buffer) { string str = buffer.ReadString(); session.uid = buffer.ReadInt(); ByteBuffer newBuffer = new ByteBuffer(); newBuffer.WriteByte((byte)ProtocalType.BINARY); newBuffer.WriteString(str); SocketUtil.SendMessage(session, Protocal.Login, newBuffer); UserUtil.Add(session.uid, session); Console.WriteLine("OnBinaryMessage--->>>" + str + session.uid); }
//If the Server has established a connection to the Server, the Servers sends a Welcome Message public static void HandleWelcomeMessage(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); int packetID = buffer.ReadInteger(); string msg = buffer.ReadString(); buffer.Dispose(); Debug.Log("Server: " + msg); StartMenuUI.instanceUI.UsernameUI.SetActive(false); StartMenuUI.instanceUI.TeamsitesUI.SetActive(true); DataSender.SendConnected(); }
public void Read(ByteBuffer buf) { PlayerId = (sbyte)buf.ReadByte(); PlayerName = buf.ReadString(); var temp = new MinecraftLocation(); var loc = new Vector3S // -- WARNING: This might cause unintended behavior!! { X = buf.ReadShort(), Z = buf.ReadShort(), Y = buf.ReadShort() }; temp.SetAsPlayerCoords(loc); temp.Rotation = buf.ReadByte(); temp.Look = buf.ReadByte(); Location = temp; }
private static void Packet_DropCardOnTableErrorCantDropThisCard(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); //Skip packetId buffer.ReadLong(); //read card string cardCode = buffer.ReadString(); //Invoke callback on observers FoolObservable.OnDropCardOnTableErrorCantDropThisCard(cardCode); }
private static void HandleTakeDamages(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); int fromID = buffer.ReadInteger(); buffer.ReadString(); float damages = buffer.ReadFloat(); buffer.Dispose(); NetworkManager.GetLocalPlayer().GetComponent <Player>().TakeDamages(damages, fromID); }
public override SPacket ParsePacket(ByteBuffer buffer) { Last = buffer.ReadUShort() != 0; Count = buffer.ReadUShort(); Data = new ParDefData[Count]; for (int i = 0; i < Count; i++) { Data[i] = new ParDefData( buffer.ReadShort(), buffer.ReadShort(), buffer.ReadShort(), buffer.ReadShort(), buffer.ReadString(8)); } return(this); }
public void Process(byte[] buffer, IConnection connection) { var pData = Authentication.Players[connection.Index]; var msg = new ByteBuffer(buffer); var name = msg.ReadString(); if (name.Length > 0) { var warp = new AdministratorWarp() { Player = Authentication.Players[connection.Index] }; warp.MovePlayerToMe(Authentication.FindByCharacter(name)); } }
public void HandleSSyncingPlayerMovement(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); // contains playerID, X,Y,Z in this other buffer.ReadInt(); string playerID = buffer.ReadString(); //Debug.Log("*********entrou******"+playerID); float x, y, z = 0; x = buffer.ReadFloat(); y = buffer.ReadFloat(); z = buffer.ReadFloat(); tst[playerID].GetComponent <NavMeshAgent>().SetDestination(new Vector3(x, y, z)); }
private static void CP_NetView(string id, byte[] data) { long packetnum; ByteBuffer buffer; buffer = new ByteBuffer(); buffer.WriteBytes(data); packetnum = buffer.ReadLong(); string myid = buffer.ReadString(); float x = buffer.ReadFloat(); float y = buffer.ReadFloat(); float z = buffer.ReadFloat(); Console.WriteLine(string.Format("Client {0} sent {1}", myid, Enum.GetName(typeof(PacketType), packetnum))); Server.Send(buffer.ToArray(), myid, true); buffer.Dispose(); }
public static ByteBuffer tryToLogic(string key) { ByteBuffer buffer = NetUtil.getInstance.find(key); if (buffer != null) { NetUtil.getInstance.remove(key); int result = buffer.ReadInt(); if (result == 1) { string tip = buffer.ReadString(); DialogUtil.tip(tip); return(null); } } return(buffer); }
public static void HandleStartGame(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); int packetID = buffer.ReadInt(); int size = buffer.ReadInt(); Debug.Log("Game Has Started!\nDrawing " + size + " cards."); for (int x = 0; x < size; x++) { Debug.Log("Card ID: " + buffer.ReadString()); } buffer.Dispose(); }
public void OnMessage(ClientSession session, ByteBuffer buffer) { string str = buffer.ReadString(); int uid = buffer.ReadInt(); ushort commandId = (ushort)Protocal.Login; ByteBuffer newBuffer = new ByteBuffer(); newBuffer.WriteShort(commandId); newBuffer.WriteByte(1); newBuffer.WriteString(str); SocketUtil.SendMessage(session, newBuffer); session.uid = uid; UserUtil.Add(uid, session); Console.WriteLine("OnMessage--->>>" + str + uid); }
public static DealBody read(ByteBuffer data) { DealBody item = new DealBody(); item.id = data.ReadLong(); item.seller = data.ReadByte() == 1; item.uid = data.ReadLong(); item.userName = data.ReadString(); item.icon = data.ReadString(); item.time = data.ReadString(); item.validTime = data.ReadString(); item.typeStr = data.ReadByte() == 0 ? "入库" : "现货"; item.bourse = data.ReadString(); item.stampName = data.ReadString(); item.monad = data.ReadString(); item.curNum = data.ReadInt(); item.price = float.Parse(data.ReadString()); item.context = data.ReadString(); item.helpFlag = data.ReadByte() == 1; item.revoke = data.ReadByte() == 1; item.isLock = data.ReadByte() == 1; int revertLen = data.ReadInt(); for (int j = 0; j < revertLen; j++) { Revert revert = Revert.read(data); item.reverts.Add(revert); } int orderLen = data.ReadInt(); for (int j = 0; j < orderLen; j++) { Order order = Order.read(data); order.item = item; item.orders.Add(order); } return(item); }
/// <summary> /// Initialize the public key from a blob of binary data. /// </summary> /// <param name="blob">The encoded public key</param> /// <param name="start">The location in the array where the encoded data starts</param> /// <param name="len">The length of the encoded data</param> public void Init(byte[] blob, int start, int len) { // Extract the key information ByteBuffer buffer = new ByteBuffer(blob); buffer.Skip(start); String header = buffer.ReadString(); if (!header.Equals("ssh-rsa")) { throw new SSHException("Invalid ssh-rsa key", SSHException.BAD_API_USAGE); } publicExponent = buffer.ReadBigInteger(); modulus = buffer.ReadBigInteger(); }
public bool TryRead(ByteBuffer bb) { int endPos; if (!ByteBuffer.StartTryReadPacket(bb, out endPos, 0)) { return(false); } ByteBuffer.ReadUlong(bb); ByteBuffer.ReadString(bb); ByteBuffer.ReadInt(bb); ByteBuffer.ReadUint(bb); ByteBuffer.ReadUlong(bb); ByteBuffer.EndReadPacket(bb, endPos); return(true); }
private static void CP_Leaving(string id, byte[] data) { long packetnum; ByteBuffer buffer; buffer = new ByteBuffer(); buffer.WriteBytes(data); packetnum = buffer.ReadLong(); string myid = buffer.ReadString(); for (int i = 0; i < Server.clients.Count; i++) { if (Server.clients[i].id == myid) { Server.clients[i].CloseSocket(); } } buffer.Dispose(); }
/// <summary> /// 接收到消息 /// </summary> /// <param name="ms"></param> void OnReceivedMessage(MemoryStream ms) { BinaryReader r = new BinaryReader(ms); byte[] message = r.ReadBytes((int)(ms.Length - ms.Position)); ByteBuffer buffer = new ByteBuffer(message); int mainId = buffer.ReadInt(); mainId = System.Net.IPAddress.NetworkToHostOrder(mainId); string content = null; if ((message.Length - 4) > 0) { content = buffer.ReadString(message.Length - 4); } Log("收到消息" + mainId); InQueue.Enqueue(new KeyValuePair <Protocol.PROTOCOL, string>((Protocol.PROTOCOL)mainId, content)); }
private static int ReadString(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 1); ByteBuffer byteBuffer = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer)); string str = byteBuffer.ReadString(); LuaDLL.lua_pushstring(L, str); result = 1; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
public static void Read(ByteBuffer bfs, VisualNode node) { node.Title = bfs.ReadString(); node.rect.x = bfs.ReadFloat(); node.rect.y = bfs.ReadFloat(); node.rect.width = bfs.ReadFloat(); node.rect.height = bfs.ReadFloat(); int count = bfs.ReadByte(); for (int i = 0; i < count; ++i) { var field = FieldNode.Read(bfs.ReadBytes()); field.Target = node; node.fields.Add(field); } node.currentFlow = FlowNode.Read(bfs.ReadBytes()); node.currentFlow.Target = node; }
/// <summary> /// Handles SevrerPacketId.Packet_TalonData /// </summary> private static void Packet_TalonData(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); //Skip packetId buffer.ReadLong(); //Read talon len int talonLength = buffer.ReadInteger(); //Read trump card string trumpCard = buffer.ReadString(); //Invoke callback on observers FoolObservable.OnTalonData(talonLength, trumpCard); }
public void PetUpdate(ByteBuffer buff) { SummonType = buff.ReadUInt32(); ID = buff.ReadUInt32(); X = buff.ReadUInt32(); Y = buff.ReadUInt32(); Z = buff.ReadUInt32(); buff.ReadString(); //title Cur_Fed = buff.ReadUInt32(); Max_Fed = buff.ReadUInt32(); Cur_HP = buff.ReadUInt32(); Max_HP = buff.ReadUInt32(); Cur_MP = buff.ReadUInt32(); Max_MP = buff.ReadUInt32(); Level = buff.ReadUInt32(); XP = buff.ReadUInt64(); XP_ThisLevel = buff.ReadUInt64(); XP_NextLevel = buff.ReadUInt64(); if (Globals.gamedata.Chron >= Chronicle.CT3_0) { buff.ReadUInt32(); //00 00 00 00 } }
public void Load_Pet(ByteBuffer buff) { SummonType = buff.ReadUInt32(); //1 = summon, 2 = pet ID = buff.ReadUInt32(); NPCID = buff.ReadUInt32(); isAttackAble = buff.ReadUInt32();//attackable = 0 X = buff.ReadUInt32(); Y = buff.ReadUInt32(); Z = buff.ReadUInt32(); Heading = buff.ReadInt32(); buff.ReadUInt32();//0x00 MatkSpeed = buff.ReadUInt32(); PatkSpeed = buff.ReadUInt32(); RunSpeed = buff.ReadUInt32(); WalkSpeed = buff.ReadUInt32(); SwimRunSpeed = buff.ReadUInt32(); SwimWalkSpeed = buff.ReadUInt32(); flRunSpeed = buff.ReadUInt32(); flWalkSpeed = buff.ReadUInt32(); if (Globals.gamedata.Chron >= Chronicle.CT1) { FlyRunSpeed = buff.ReadUInt32(); FlyWalkSpeed = buff.ReadUInt32(); } MoveSpeedMult = System.Convert.ToSingle(buff.ReadDouble()); AttackSpeedMult = System.Convert.ToSingle(buff.ReadDouble()); CollisionRadius = System.Convert.ToSingle(buff.ReadDouble()); CollisionHeight = System.Convert.ToSingle(buff.ReadDouble()); LWeapon = buff.ReadUInt32(); Armor = buff.ReadUInt32(); RWeapon = buff.ReadUInt32(); HasOwner = buff.ReadByte(); //owneronline isRunning = buff.ReadByte(); isInCombat = buff.ReadByte(); isAlikeDead = buff.ReadByte(); isSummoned = buff.ReadByte(); //isSummoned 0=teleported 1=default 2=summoned if (Globals.gamedata.Chron >= Chronicle.CT3_0) { buff.ReadUInt32(); //FF FF FF FF } Name = buff.ReadString(); if (string.IsNullOrWhiteSpace(Name)) { Name = Util.GetNPCName(NPCID);//"Unnamed Pet"; } if (Globals.gamedata.Chron >= Chronicle.CT3_0) { buff.ReadUInt32(); //FF FF FF FF } Title = buff.ReadString(); //OwnerName buff.ReadUInt32();//1 PvPFlag = buff.ReadUInt32(); Karma = buff.ReadInt32(); Cur_Fed = buff.ReadUInt32(); Max_Fed = buff.ReadUInt32(); Cur_HP = buff.ReadUInt32(); Max_HP = buff.ReadUInt32(); Cur_MP = buff.ReadUInt32(); Max_MP = buff.ReadUInt32(); SP = buff.ReadUInt32(); Level = buff.ReadUInt32(); XP = buff.ReadUInt64(); XP_ThisLevel = buff.ReadUInt64(); XP_NextLevel = buff.ReadUInt64(); Cur_Load = buff.ReadUInt32(); Max_Load = buff.ReadUInt32(); Patk = buff.ReadUInt32(); PDef = buff.ReadUInt32(); Accuracy = buff.ReadUInt32();// p Evasion = buff.ReadUInt32();//p Focus = buff.ReadUInt32();//p Matk = buff.ReadUInt32(); MDef = buff.ReadUInt32(); buff.ReadUInt32();//m acu buff.ReadUInt32();//m eva buff.ReadUInt32();//m crit buff.ReadUInt32();// speed buff.ReadUInt32();//patak sped buff.ReadUInt32();// cast /*if (Globals.gamedata.Chron < Chronicle.CT3_0) { AbnormalEffects = buff.ReadUInt32(); //AbnormalEffect bleed=1; poison=2; poison & bleed=3; flame=4; } else { buff.ReadUInt32(); //?? }*/ Mountable = buff.ReadUInt16(); buff.ReadByte(); buff.ReadUInt16(); if (Globals.gamedata.Chron >= Chronicle.CT1) { TeamCircle = buff.ReadByte(); /*if (Globals.gamedata.Chron >= Chronicle.CT3_0) { //buff.ReadUInt32(); //00 00 00 00 buff.ReadUInt16(); AbnormalEffects = buff.ReadUInt32(); buff.ReadUInt32(); //00 00 00 00 buff.ReadUInt16(); //00 00 00 00 }*/ SSUsage = buff.ReadUInt32(); SPSUSage = buff.ReadUInt32(); Form = buff.ReadUInt32(); buff.ReadUInt32();//0x00 if (Globals.gamedata.Chron >= Chronicle.CT3_0) { //buff.ReadUInt16(); //00 00 try { buff.ReadUInt32(); //00 00 buff.ReadUInt32(); //02 00 00 00 current pet points buff.ReadUInt32(); //06 00 00 00 max pet points uint abn_count = buff.ReadUInt32(); if (abn_count < 30) // well ... its oddi wayso :P { _AbnEffects.Add(buff.ReadUInt32()); } } catch { } } } else { HasOwner = buff.ReadByte(); SSUsage = buff.ReadUInt32(); Form = buff.ReadUInt32(); buff.ReadUInt32();//0x00 } }