/// <summary> /// Gets game server current configuration /// </summary> /// <param name="response">Underlaying in and out streams</param> /// <param name="token">Token for authentication</param> private void GetSettings(HttpListenerContext response, string token) { List <byte> buffer = new List <byte>(); buffer.Add((int)EnumsServer.Enums.AllEnums.HGetSettings); //Mudar buffer.AddRange(BitConverter.GetBytes(Encoding.ASCII.GetBytes(token).Length)); buffer.AddRange(Encoding.ASCII.GetBytes(token)); SendToGameServer(buffer.ToArray()); while (!client.GetStream().DataAvailable) { Thread.Sleep(50); } byte[] dataFromServer = new byte[4096]; client.GetStream().Read(dataFromServer, 0, dataFromServer.Length); ByteBuffer bf = new ByteBuffer(); bf.WriteBytes(dataFromServer); string json = "{ port:" + bf.ReadInt() + ", concurrent_players: " + bf.ReadInt() + "}"; SendToClient(response, json, 200); }
private string ConvertToJson(byte[] data) { List <PlayerJson> players = new List <PlayerJson>(); ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); int numberPlayers = buffer.ReadInt(); if (numberPlayers == 0) { return(""); } for (int i = 0; i < numberPlayers; i++) { PlayerJson p = new PlayerJson(); p.username = buffer.ReadString(); p.char_name = buffer.ReadString(); p.player_IP = buffer.ReadString(); p.current_playtime = buffer.ReadInt(); //p.total_playtime = buffer.ReadInt(); players.Add(p); } return(JsonConvert.SerializeObject(players)); }
/// <summary> /// /// </summary> /// <param name="block"></param> private void ProcessBlockBufferData(ByteBuffer block) { var realenginer = (ServiceLocator.Locator.Resolve <IRealTagConsumer>() as RealEnginer); if (realenginer == null || realenginer.Memory == null) { return; } var start = block.ReadInt(); var size = block.ReadInt(); //LoggerService.Service.Info("ProcessBlockBufferData", "block start" +start +", size:"+size); try { if (realenginer.Memory != null && (start + size < realenginer.Memory.Length)) { block.CopyTo(realenginer.MemoryHandle, block.ReadIndex, start, size); // Buffer.BlockCopy(block.Array, block.ArrayOffset + block.ReaderIndex, realenginer.Memory, start, size); } else { //内存数据不匹配,需要重新加载数据库 //ReloadDatabaseAction?.BeginInvoke(true,true,true,null,null); } } catch { } block.ReadIndex += size; block.UnlockAndReturn(); //block.SetReaderIndex(block.ReaderIndex + size); //block.ReleaseBuffer(); }
// Update is called once per frame void Update() { if (pushs.Count == 0) { return; } if (!ConfirmUtil.isConfirmShow() && !LoadUtil.isActivity() && !DialogUtil.isPopTips()) { if (!isOpen) { tryToOpenPush(); } } ByteBuffer buffer = MyUtilTools.tryToLogic("DealGrab"); if (buffer != null) { DialogUtil.tip("抢单成功", true); } buffer = MyUtilTools.tryToLogic("DealFavorite"); if (buffer != null) { int type = buffer.ReadInt(); int len = buffer.ReadInt(); MainData.instance.user.favorites.Clear(); for (int i = 0; i < len; i++) { long value = buffer.ReadLong(); MainData.instance.user.favorites.Add(value); } DialogUtil.tip(type == 0 ? "收藏成功" : "取消收藏成功", true); } }
/// <summary> /// /// </summary> /// <param name="block"></param> private void ProcessSingleBufferDataByMemoryCopy(ByteBuffer block) { var realenginer = (ServiceLocator.Locator.Resolve <IRealTagConsumer>() as RealEnginer); var mTagManager = ServiceLocator.Locator.Resolve <ITagManager>(); var count = block.ReadInt(); for (int i = 0; i < count; i++) { var vid = block.ReadInt(); if (vid < 0) { Debug.Print("Invaild value!"); } if (mTagManager != null) { var tag = mTagManager.GetTagById(vid); if (tag != null && realenginer.Memory != null) { try { block.CopyTo(realenginer.MemoryHandle, block.ReadIndex, tag.ValueAddress, tag.ValueSize); // Buffer.BlockCopy(block.Array, block.ArrayOffset + block.ReaderIndex, realenginer.Memory, (int)tag.ValueAddress, tag.ValueSize); } catch { } block.ReadIndex += tag.ValueSize; //block.SetReaderIndex(block.ReaderIndex + tag.ValueSize); } } } block.UnlockAndReturn(); }
public override void Setup_BeforeAdd(ByteBuffer buffer, int beginPos) { base.Setup_BeforeAdd(buffer, beginPos); buffer.Seek(beginPos, 4); string str = buffer.ReadS(); if (str != null) { inputTextField.promptText = str; } str = buffer.ReadS(); if (str != null) { inputTextField.restrict = str; } int iv = buffer.ReadInt(); if (iv != 0) { inputTextField.maxLength = iv; } iv = buffer.ReadInt(); if (iv != 0) { inputTextField.keyboardType = iv; } if (buffer.ReadBool()) { inputTextField.displayAsPassword = true; } }
override protected void AddStatus(string pageId, ByteBuffer buffer) { GearXYValue gv; if (pageId == null) { gv = _default; } else { gv = new GearXYValue(); _storage[pageId] = gv; } gv.x = buffer.ReadInt(); gv.y = buffer.ReadInt(); if (buffer.version >= 2) { gv.px = buffer.ReadFloat(); gv.py = buffer.ReadFloat(); } else { gv.px = gv.x / _owner.parent.width; gv.py = gv.y / _owner.parent.height; } }
private void UnPackProtocol(byte[] msg_bytes) { ByteBuffer buffer = new ByteBuffer(Encrypt.Decode(msg_bytes, Encrypt.DefaultKey)); //读出附加位 int addition = buffer.ReadInt(); //读出用户ID列表 int list_lenght = buffer.ReadInt(); //读出协议体 byte[] protocol_bytes = buffer.ReadBytes((int)buffer.RemainingBytes()); IMessage protocol = Protocol.Decode(protocol_bytes); buffer.Close(); if (protocol != null) { Debug.Log("客户端接收消息:" + protocol.GetType() + " 数据:" + protocol.ToString()); lock (msg_lock) { this.protocol_list.Add(protocol); } } }
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos) { base.Setup_AfterAdd(buffer, beginPos); if (!buffer.Seek(beginPos, 6)) { Update(); return; } if ((ObjectType)buffer.ReadByte() != packageItem.objectType) { Update(); return; } _value = buffer.ReadInt(); _max = buffer.ReadInt(); if (buffer.version >= 2) { _min = buffer.ReadInt(); } Update(); }
/// <summary> /// 解析数据 /// </summary> public void Parse(byte[] bytes) { if (bytes == null) { throw new Exception("Fatal error : Param is null."); } if (_isParse) { throw new Exception("Fatal error : Package is already parse."); } _isParse = true; // 字节缓冲区 ByteBuffer bb = new ByteBuffer(bytes); // 读取版本号 Version = bb.ReadInt(); // 读取元素总数 int elementCount = bb.ReadInt(); Elements = new Dictionary <string, PatchElement>(elementCount); int tableLine = 1; const int headMarkAndSize = 6; //注意:short字节数+int字节数 while (bb.IsReadable(headMarkAndSize)) { // 检测行标记 short tableHead = bb.ReadShort(); if (tableHead != TableStreamHead) { throw new Exception($"PatchManifest table stream head is invalid. Table line is {tableLine}"); } // 检测行大小 int tableSize = bb.ReadInt(); if (!bb.IsReadable(tableSize) || tableSize > TableStreamMaxLen) { throw new Exception($"PatchManifest table stream size is invalid. Table size is {tableSize},Table line {tableLine}"); } // 读取行内容 string fileName = bb.ReadUTF(); string fileMD5 = bb.ReadUTF(); long fileSizeBytes = bb.ReadLong(); int fileVersion = bb.ReadInt(); List <string> variantList = bb.ReadListUTF(); // 添加到集合 if (Elements.ContainsKey(fileName)) { throw new Exception($"Fatal error : PatchManifest has same element : {fileName}"); } Elements.Add(fileName, new PatchElement(fileName, fileMD5, fileSizeBytes, fileVersion, variantList)); ++tableLine; } }
/// <summary> /// Changes the server's cofiguration file /// </summary> /// <param name="data">Byte array containing new server configuration</param> private void HChangeSettings(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadByte(); int nOfPlayers = buffer.ReadInt(); int port = buffer.ReadInt(); byte restart = buffer.ReadByte(); string configFile = "port=" + port + System.Environment.NewLine + "NumberOfPlayers=" + nOfPlayers; try { StreamWriter writer = new StreamWriter("config.txt"); writer.Write(configFile); writer.Close(); } catch (Exception) { SendDefaultRespose(false, clNo); } SendDefaultRespose(true, clNo); if (restart == 1) { HRestartServer(); } }
internal AutoKey(AutoKeys autoKeys, ByteBuffer os) { this.AutoKeys = autoKeys; Name = os.ReadString(); LocalId = os.ReadInt(); LocalStep = os.ReadInt(); Current = os.ReadLong(); }
public void Load(ByteBuffer ba) { ba.ReadInt(); pixelWidth = ba.ReadInt(); scale = 1.0f / ba.ReadByte(); pixels = ba.buffer; pixelsLength = ba.ReadInt(); pixelsOffset = ba.position; ba.Skip(pixelsLength); }
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos) { base.Setup_BeforeAdd(buffer, beginPos); buffer.Seek(beginPos, 5); _layout = (GroupLayoutType)buffer.ReadByte(); _lineGap = buffer.ReadInt(); _columnGap = buffer.ReadInt(); }
public int cp; //差评次数 public void deserialize(ByteBuffer buffer) { curValue = float.Parse(buffer.ReadString()); maxValue = float.Parse(buffer.ReadString()); tempMaxValue = float.Parse(buffer.ReadString()); totalDealValue = float.Parse(buffer.ReadString()); hp = buffer.ReadInt(); zp = buffer.ReadInt(); cp = buffer.ReadInt(); }
public void Load(ByteBuffer ba) { ba.ReadInt(); pixelWidth = ba.ReadInt(); scale = 1.0f / ba.ReadByte(); int len = ba.ReadInt(); pixels = new byte[len]; for (int i = 0; i < len; i++) pixels[i] = ba.ReadByte(); }
override protected void AddStatus(string pageId, ByteBuffer buffer) { if (pageId == null) { _default = buffer.ReadInt(); } else { _storage[pageId] = buffer.ReadInt(); } }
public void HandleSSendingMainToAlreadyConnected(int packetNum, byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); int PlayerIndex = buffer.ReadInt(); packetNum = buffer.ReadInt(); //otherPlayer.name = Convert.ToString(PlayerIndex); }
public void HandleSSendingAlreadyConnectedToMain(int packetNum, byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); packetNum = buffer.ReadInt(); int PlayerIndex = buffer.ReadInt(); Instantiate(npc,spawnpoint, new Quaternium(0,0,0,0); npcs.add(PlayerIndex,npc); /*playerID = PlayerIndex; /*Globals g = Globals.getIstance(); g.MyIndex = PlayerIndex;*/ }
static void AcceptConnection(int _connectionID, byte[] _data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(_data); int packetIdentifier = buffer.ReadInt(); int status = buffer.ReadInt(); LogManager.WriteClientMessage(status.ToString(), _connectionID); buffer.Dispose(); //NetworkSendData.SendPlayerJoin(_connectionID); }
/// <summary> /// /// </summary> /// <param name="block"></param> private void ProcessValueChangeNotify(string clientId, ByteBuffer block) { try { int minid = block.ReadInt(); int maxid = block.ReadInt(); HashSet <int> ids = new HashSet <int>(); for (int i = minid; i <= maxid; i++) { ids.Add(i); lock (mMonitors) { if (!mMonitors.ContainsKey(i)) { var vtag = mTagManager.GetTagById(i); if (vtag != null) { mtmp.Add(i, new MonitorTag() { Value = 0, RefCount = 1, Type = vtag.Type }); } } else { mMonitors[i].IncRef(); } } } if (mCallBackRegistorIds.ContainsKey(clientId)) { mCallBackRegistorIds[clientId] = ids; } else { mCallBackRegistorIds.Add(clientId, ids); } lock (mDataCounts) if (!mDataCounts.ContainsKey(clientId)) { mDataCounts.Add(clientId, 0); } Parent.AsyncCallback(clientId, ToByteBuffer(ApiFunConst.RealDataRequestFun, 1)); } catch (Exception ex) { Parent.AsyncCallback(clientId, ToByteBuffer(ApiFunConst.RealDataRequestFun, 0)); Debug.Print(ex.Message); } }
public TDic Load() { buffer = LoadByte <TChild>(); //读出行列 rows = buffer.ReadInt(); cols = buffer.ReadInt(); //读名称 nameList = ReadNameList(buffer, cols); //读类型 typeList = ReadTypeList(buffer, cols); return(Init()); }
//处理命令3-登录账号 3 i-s i-s public static void order_3(ByteBuffer buff, Socket mClientSocket) { //读取剩余二进制数据中的账户字符串长度 int accountLen = buff.ReadInt(); //读取账户字符串 string account = buff.ReadString(accountLen); //读取密码字符串长度 int passLen = buff.ReadInt(); //读取密码字符串 string password = buff.ReadString(passLen); Console.WriteLine("从客户端接收到的账户长度为{0},账户为{1},密码长度是{2},密码是{3}", accountLen, account, passLen, password); serverSendMessage(mClientSocket, "用户账户登录成功"); }
public static void HandleData(byte[] data) { byte[] buffer = (byte[])data.Clone(); int packetLength = 0; if (playerBuffer == null) { playerBuffer = new ByteBuffer(); } playerBuffer.WriteBytes(buffer); if (playerBuffer.GetBufferSize() == 0) { playerBuffer.ClearBuffer(); return; } if (playerBuffer.GetBufferSize() >= 4) { packetLength = playerBuffer.ReadInt(false); if (packetLength <= 0) { playerBuffer.ClearBuffer(); return; } } while (packetLength > 0 & packetLength <= playerBuffer.GetBufferSize() - 4) { if (packetLength <= playerBuffer.GetBufferSize() - 4) { playerBuffer.ReadInt(); data = playerBuffer.ReadBytes(packetLength); HandleDataPackets(data); } packetLength = 0; if (playerBuffer.GetRemainingBufferLength() >= 4) { packetLength = playerBuffer.ReadInt(false); if (packetLength <= 0) { playerBuffer.ClearBuffer(); return; } } } }
/// <summary> /// /// </summary> /// <param name="clientId"></param> /// <param name="data"></param> private void ProcessRequestStatisticsDataByTimePointByMemory(string clientId, ByteBuffer data) { int id = data.ReadInt(); int count = data.ReadInt(); List <DateTime> times = new List <DateTime>(); for (int i = 0; i < count; i++) { times.Add(new DateTime(data.ReadLong())); } ByteBuffer re = DBRuntime.Proxy.DatabaseRunner.Manager.Proxy.QueryStatisticsHisDataByMemory(id, times); re.UnLock(); Parent.AsyncCallback(clientId, re); }
public void Decode(ByteBuffer bb) { for (int count = bb.ReadInt(); count > 0; --count) { var table = new Table(); table.Decode(bb); Tables.Add(table.Name, table); } for (int count = bb.ReadInt(); count > 0; --count) { var bean = new Bean(); bean.Decode(bb); Beans.Add(bean.Name, bean); } }
/// <summary> /// /// </summary> /// <param name="clientId"></param> /// <param name="block"></param> private void ProcessGetRealDataByMemoryCopy(string clientId, ByteBuffer block) { int count = block.ReadInt(); List <int> cc = new List <int>(count); for (int i = 0; i < count; i++) { cc.Add(block.ReadInt()); } var re = Parent.Allocate(ApiFunConst.RealDataRequestFun, count * 34); ProcessRealDataByMemoryCopy(cc, re); Parent.AsyncCallback(clientId, re); }
/// <summary> /// /// </summary> /// <param name="clientId"></param> /// <param name="block"></param> private void ProcessGetRealData2ByMemoryCopy(string clientId, ByteBuffer block) { int sid = block.ReadInt(); int eid = block.ReadInt(); List <int> cc = new List <int>(eid - sid); for (int i = sid; i <= eid; i++) { cc.Add(i); } var re = Parent.Allocate(ApiFunConst.RealDataRequestFun, cc.Count * 34); ProcessRealDataByMemoryCopy(cc, re); Parent.AsyncCallback(clientId, re); }
//接收群聊回包数据 public void OnRecvWorldChat(byte[] Byte) { ByteBuffer buffer = new ByteBuffer(Byte); int size = Byte.Length; int typeId = buffer.ReadInt(); s2c_world_chat_reply reply = PackCodec.Deserialize <s2c_world_chat_reply>(buffer.ReadBytes(size - sizeof(Int32))); UInt32 id = reply.id; string text = reply.content; time_section timeSection = reply.time; UInt32 year = timeSection.year; UInt32 month = timeSection.month; UInt32 day = timeSection.day; UInt32 hour = timeSection.hour; UInt32 minu = timeSection.minu; UInt32 sec = timeSection.sec; string time = year + "/" + month + "/" + day + " " + hour + ":" + minu + ":" + sec; content.text += "<color=#ff0000ff>世界 </color>"; content.text += "<color=#000000ff>用户: </color>"; Debug.Log("content: " + content.text); if (id == GameMgr.instance.id) { content.text += "<color=#ff0000ff>" + id + "(自己) " + "</color>"; } else { content.text += "<color=#0000ff>" + id + " " + "</color>"; } content.text += "<color=#00ffffff>" + time + "\r\n" + "</color>"; content.text += "<color=#000000ff>" + text + "\r\n" + "</color>"; }
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos) { base.Setup_BeforeAdd(buffer, beginPos); buffer.Seek(beginPos, 5); _layout = (GroupLayoutType)buffer.ReadByte(); _lineGap = buffer.ReadInt(); _columnGap = buffer.ReadInt(); if (buffer.version >= 2) { _excludeInvisibles = buffer.ReadBool(); _autoSizeDisabled = buffer.ReadBool(); _mainChildIndex = buffer.ReadShort(); } }