public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var add = false; var index = msg.ReadInt32(); var accountId = msg.ReadInt32(); var characterId = msg.ReadInt32(); var character = Global.FindCharacterById(characterId); if (character == null) { add = true; character = new Character(); } character.AccountId = accountId; character.CharacterId = characterId; ReadCharacterData(ref character, ref msg); msg.Flush(); msg = null; InsertCharacterData(index, ref character, connection); AddCharacterData(ref character, add); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var count = msg.ReadInt32(); var inventory = new List <Inventory>(); for (var n = 1; n <= count; n++) { inventory.Add( new Inventory { Index = n, ItemID = msg.ReadInt32(), ItemValue = msg.ReadInt32(), ItemLevel = msg.ReadInt32(), ItemBound = msg.ReadByte() } ); } msg.Flush(); msg = null; AddCharacterInventory(characterId, ref inventory); }
//-------------------------------------------// //------------ Serialization --------------// //-------------------------------------------// /// <summary> /// Serialize a node with the specified writer formatted. /// </summary> public static bool Serialize(Node node, ByteBuffer writer) { bool success = Serialize(node, writer, string.Empty); writer.Flush(); return(success); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var count = msg.ReadInt32(); var hotbar = new List <Hotbar>(); for (int n = 1; n <= count; n++) { hotbar.Add( new Hotbar() { Index = n, Value = msg.ReadInt32(), Type = msg.ReadByte() } ); } msg.Flush(); msg = null; AddCharacterHotbar(characterId, ref hotbar); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var count = msg.ReadInt32(); var title = new List <Title>(); for (var n = 1; n <= count; n++) { title.Add( new Title() { Index = n, ID = msg.ReadInt32() } ); } msg.Flush(); msg = null; AddCharacterTitle(characterId, ref title); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var craftCount = msg.ReadInt32(); var recipeCount = msg.ReadInt32(); var craft = new List <Craft>(); for (int n = 1; n <= craftCount; n++) { craft.Add( new Craft() { Index = (byte)n, Type = msg.ReadByte(), Level = msg.ReadInt32(), Experience = msg.ReadInt32(), Recipes = new List <int>() } ); for (int i = 0; i < recipeCount; i++) { craft[n - 1].Recipes.Add(msg.ReadInt32()); } } ; msg.Flush(); msg = null; AddCharacterCraft(characterId, ref craft); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var count = msg.ReadInt32(); var currency = new List <Currency>(); for (int n = 0; n <= count; n++) { currency.Add( new Currency() { Index = n, Value = msg.ReadInt32() } ); } msg.Flush(); msg = null; AddCharacterCurrency(characterId, ref currency); }
public void Send(IConnection connection) { ((Connection)connection).Send(msg, GetType().Name); msg.Flush(); msg = null; }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var count = msg.ReadInt32(); var spell = new List <Spell>(); for (var n = 1; n <= count; n++) { spell.Add( new Spell() { Index = n, ID = msg.ReadInt32(), Uses = msg.ReadInt32(), Level = msg.ReadInt32() } ); } msg.Flush(); msg = null; AddCharacterSpell(characterId, ref spell); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var achievementCount = msg.ReadInt32(); var achievement = new List <Achievement>(); for (var n = 1; n <= achievementCount; n++) { var value = new Achievement() { Index = n, Value = msg.ReadByte() }; achievement.Add(value); } msg.Flush(); msg = null; AddCharacterAchievement(characterId, ref achievement); }
static int Flush(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); ByteBuffer obj = (ByteBuffer)LuaScriptMgr.GetNetObjectSelf(L, 1, "ByteBuffer"); obj.Flush(); return(0); }
static int Flush(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); ByteBuffer obj = LuaScriptMgr.GetNetObject <ByteBuffer>(L, 1); obj.Flush(); return(0); }
public IEnumerable <LogEntryEventArgs> ReadAsEnumerable() { var readBuffer = new ByteBuffer(BufferSize); var entryBuffer = new ByteBuffer(EntryMaxSize); var totalRead = 0; LogMessage(LogLevel.Debug, $"Reading file {Filename} of size {new FileInfo(Filename).Length}"); using (var fileStream = new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { _fileEnded = false; while (!_fileEnded) { var offset = 0; var readCount = readBuffer.ReadStream(fileStream); totalRead += readCount; LogMessage(LogLevel.Trace, $"Read {readCount} bytes ({totalRead} total)"); _fileEnded = !readBuffer.IsFull; if (_fileEnded) { LogMessage(LogLevel.Trace, $"Got only {readBuffer.Count} bytes out of {readBuffer.Capacity}"); } var boundIndex = FindEntryBound(readBuffer.Data, readBuffer.Count); Console.WriteLine(boundIndex.Item1); while (boundIndex.Item1 != BoundNotFound) { entryBuffer.CopyFrom(readBuffer, boundIndex.Item1); offset += boundIndex.Item1 + boundIndex.Item2; LogMessage(LogLevel.Info, $"Current block offset: {offset}"); readBuffer.TruncateStart(boundIndex.Item1 + boundIndex.Item2); var slice = new byte[entryBuffer.Count - 1]; Array.Copy(entryBuffer.Data, slice, entryBuffer.Count - 1); entryBuffer.Flush(); var entry = EntryTokenizer.ParseEntry(slice); if (entry != null) { yield return(entry); } else { var str = Encoding.UTF8.GetString(slice); LogMessage(LogLevel.Warning, $"Failed to parse {str}"); } boundIndex = FindEntryBound(readBuffer.Data, readBuffer.Count); } entryBuffer.CopyFrom(readBuffer); LogMessage(LogLevel.Info, $"Data left: {readBuffer.ToUtf8String()}"); readBuffer.Flush(); } LogMessage(LogLevel.Debug, "File ended"); } }
public void Process(byte[] buffer, IConnection connection) { var pData = Authentication.Players[connection.Index]; if (pData.AccessLevel < AccessLevel.Administrator) { return; } var msg = new ByteBuffer(buffer); var conversationId = msg.ReadInt32(); if (conversationId <= 0 || conversationId > Configuration.MaxConversations) { msg.Flush(); return; } var conversation = new Conversation() { Id = conversationId, Name = msg.ReadString(), ChatCount = msg.ReadInt32() }; conversation.Chats = new Dictionary <int, Chat>(); for (var i = 1; i <= conversation.ChatCount; i++) { conversation.Chats.Add(i, new Chat()); conversation.Chats[i].Conversation = msg.ReadString(); for (var n = 1; n <= Configuration.MaxConversationOptions; n++) { conversation.Chats[i].RText[n] = msg.ReadString(); conversation.Chats[i].RTarget[n] = msg.ReadInt32(); } conversation.Chats[i].Event = msg.ReadInt32(); conversation.Chats[i].Data1 = msg.ReadInt32(); conversation.Chats[i].Data2 = msg.ReadInt32(); conversation.Chats[i].Data3 = msg.ReadInt32(); } DataManagement.ConversationDatabase[conversationId] = conversation; DataManagement.ConversationDatabase.SaveFile(conversationId); Global.WriteLog(LogType.Game, $"Character: {pData.Character} {pData.AccessLevel.ToString()} saved conversationId {conversationId}", LogColor.Green); var updateConversation = new SpUpdateConversation(); updateConversation.Build(conversation); updateConversation.SendToAllBut(pData.Index); }
private bool ReadFromBuffer() { if (Buffer.Empty) { return(true); } MemoryStream stream = Buffer.ToStream(); try { G2Packet pack; int bRead = ReadPacket(stream, out pack); pack.RemotePeer = peer; peer.GotPacket(pack); int totalRead = (int)pack.getTotalPacketLength(); //Debug.Assert(bRead == totalRead, "ReadFromBuffer : bRead = " + bRead + " vs totalRead = " + totalRead); if (totalRead == Buffer.DataOffset) { // buffer completely and uniquely stored the packet Buffer.Flush(); } else if (totalRead < Buffer.DataOffset) { // buffer contains some other data Buffer.Dequeue(totalRead); // remove data already read return(ReadFromBuffer()); // read others packets contained } return(true); } catch (NotEnoughDataException e) { return(false); } catch (PacketException e) { // big endian for example Buffer.Flush(); return(true); } }
static int Flush(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); ByteBuffer obj = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer)); obj.Flush(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void Process(byte[] buffer, IConnection connection) { var pData = Authentication.Players[connection.Index]; if (pData.AccessLevel < AccessLevel.Administrator) { return; } var msg = new ByteBuffer(buffer); var itemId = msg.ReadInt32(); if (itemId <= 0 || itemId > Configuration.MaxItems) { msg.Flush(); return; } var item = new Item() { Name = msg.ReadString(), Description = msg.ReadString(), Sound = msg.ReadString(), Icon = msg.ReadInt32(), Type = (ItemType)msg.ReadByte(), Data1 = msg.ReadInt32(), Data2 = msg.ReadInt32(), Data3 = msg.ReadInt32(), ClassRequired = msg.ReadInt32(), AccessLevelRequired = msg.ReadInt32(), LevelRequired = msg.ReadInt32(), Price = msg.ReadInt32(), Rarity = msg.ReadByte(), BindType = msg.ReadByte(), Animation = msg.ReadInt32() }; DataManagement.ItemDatabase[itemId] = item; DataManagement.ItemDatabase.SaveFile(itemId); Global.WriteLog(LogType.Game, $"Character: {pData.Character} {pData.AccessLevel.ToString()} saved itemId {itemId}", LogColor.Green); var updateItems = new SpUpdateItem(); updateItems.Build(item); updateItems.SendToAllBut(pData.Index); }
private static int Flush(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 1); ByteBuffer byteBuffer = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer)); byteBuffer.Flush(); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
public void Process(byte[] buffer, IConnection connection) { var pData = Authentication.Players[connection.Index]; if (pData.AccessLevel < AccessLevel.Administrator) { return; } var msg = new ByteBuffer(buffer); var animationId = msg.ReadInt32(); if (animationId <= 0 || animationId > Configuration.MaxAnimations) { msg.Flush(); return; } var animation = new Animation() { Id = animationId, Name = msg.ReadString(), Sound = msg.ReadString(), }; for (var i = 0; i < Configuration.MaxAnimationLayer; i++) { animation.Sprite[i] = msg.ReadInt32(); animation.Frames[i] = msg.ReadInt32(); animation.LoopCount[i] = msg.ReadInt32(); animation.LoopTime[i] = msg.ReadInt32(); } DataManagement.AnimationDatabase[animationId] = animation; DataManagement.AnimationDatabase.SaveFile(animationId); var updateAnimations = new SpUpdateAnimation(); updateAnimations.Build(animation); updateAnimations.SendToAllBut(pData.Index); Global.WriteLog(LogType.Game, $"Character: {pData.Character} {pData.AccessLevel.ToString()} saved animationId {animationId}", LogColor.Green); }
public void Process(byte[] buffer, IConnection connection) { var pData = Authentication.Players[connection.Index]; if (pData.AccessLevel < AccessLevel.Administrator) { return; } var msg = new ByteBuffer(buffer); var npcId = msg.ReadInt32(); if (npcId <= 0 || npcId > Configuration.MaxNpcs) { msg.Flush(); return; } var npc = new Npc() { Name = msg.ReadString(), Sound = msg.ReadString(), Sprite = msg.ReadInt32(), SpawnSeconds = msg.ReadInt32(), Behaviour = msg.ReadByte(), HP = msg.ReadInt32(), Animation = msg.ReadInt32(), Level = msg.ReadInt32(), Conversation = msg.ReadInt32() }; DataManagement.NpcDatabase[npcId] = npc; DataManagement.NpcDatabase.SaveFile(npcId); Global.WriteLog(LogType.Game, $"Character: {pData.Character} {pData.AccessLevel.ToString()} saved npcId {npcId}", LogColor.Green); var updateNpc = new SpUpdateNpc(); updateNpc.Build(npc); updateNpc.SendToAllBut(pData.Index); }
static int _m_Flush(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); ByteBuffer gen_to_be_invoked = (ByteBuffer)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.Flush( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
//-------------------------------------------// /// <summary> /// On the stream to the configuration file being established. /// </summary> private void OnLoad(ByteBuffer stream) { if (stream == null) { State = AssetState.Broken; Log.Debug("Loading configuration failed '" + _path + "'."); } else { // parse the node from the stream Node = NodeSerialization.Parse(stream); State = AssetState.Loaded; stream.Flush(); Log.Info("Loaded configuration '" + _path + "'."); } _onLoad.ArgA = this; _onLoad.Run(); _lock.Release(); }
/// <summary> /// On the stream to the configuration file being established. /// </summary> private void OnSave(ByteBuffer stream) { if (stream == null) { State = AssetState.Broken; Log.Debug("Saving configuration failed '" + _path + "'."); } else { if (NodeSerialization.Serialize(Node, stream)) { Log.Info("Saved configuration '" + _path + "'."); } else { Log.Warning("Saving configuration at '" + _path + "' failed. The node serialization didn't work."); } State = AssetState.Loaded; stream.Flush(); } _lock.Release(); }
public void Process(byte[] buffer, IConnection connection) { var msg = new ByteBuffer(buffer); var characterId = msg.ReadInt32(); var count = msg.ReadInt32(); var variable = new List <Variable>(); for (var n = 1; n <= count; n++) { variable.Add( new Variable { ID = n, Value = msg.ReadInt32() } ); } msg.Flush(); msg = null; AddCharacterVariable(characterId, ref variable); }
/** * Converts an annotation structure item to a Form XObject annotation. * @param item the structure item * @throws IOException */ protected void ConvertToXObject(StructureObject item) { PdfDictionary structElem = item.GetStructElem(); if (structElem == null) { return; } PdfDictionary dict = item.GetObjAsDict(); if (dict == null || !dict.CheckType(PdfName.ANNOT)) { return; } PdfDictionary ap = dict.GetAsDict(PdfName.AP); if (ap == null) { return; } PdfNumber structParent = dict.GetAsNumber(PdfName.STRUCTPARENT); if (structParent == null) { return; } PdfStream stream = ap.GetAsStream(PdfName.N); if (stream == null) { return; } stream.Put(PdfName.STRUCTPARENT, structParent); PdfIndirectReference xobjr = ap.GetAsIndirectObject(PdfName.N); if (xobjr == null) { return; } // remove the annotation from the page for (int i = 0; i < annots.Length; i++) { PdfIndirectReference annotref = annots.GetAsIndirectObject(i); if (item.GetObjRef().Number == annotref.Number) { annots.Remove(i); break; } } // replace the existing attributes by a PrintField attribute PdfDictionary attribute = new PdfDictionary(); attribute.Put(PdfName.O, PdfName.PRINTFIELD); PdfString description = dict.GetAsString(PdfName.TU); if (description == null) { description = dict.GetAsString(PdfName.T); } if (PdfName.BTN.Equals(dict.Get(PdfName.FT))) { PdfNumber fflags = dict.GetAsNumber(PdfName.FF); if (fflags != null) { int ff = fflags.IntValue; if ((ff & PdfFormField.FF_PUSHBUTTON) != 0) { attribute.Put(PdfName.ROLE, PdfName.PB); } // I don't think the condition below will ever be true if ((ff & PdfFormField.FF_RADIO) != 0) { attribute.Put(PdfName.ROLE, PdfName.rb); } else { attribute.Put(PdfName.ROLE, PdfName.CB); } } } else { attribute.Put(PdfName.ROLE, PdfName.TV); } attribute.Put(PdfName.DESC, description); // Updating the values of the StructElem dictionary PdfString t = structElem.GetAsString(PdfName.T); if (t == null || t.ToString().Trim().Length == 0) { structElem.Put(PdfName.T, dict.GetAsString(PdfName.T)); } structElem.Put(PdfName.A, attribute); structElem.Put(PdfName.S, PdfName.P); structElem.Put(PdfName.PG, pageref); // Defining a new MCID int mcid = items.ProcessMCID(structParents, item.GetRef()); LOGGER.Info("Using MCID " + mcid); structElem.Put(PdfName.K, new PdfNumber(mcid)); // removing the annotation from the parent tree items.RemoveFromParentTree(structParent); // Adding the XObject to the page PdfName xobj = new PdfName("XObj" + structParent.IntValue); LOGGER.Info("Creating XObject with name " + xobj); xobjects.Put(xobj, xobjr); PdfArray array = dict.GetAsArray(PdfName.RECT); // Getting the position of the annotation Rectangle rect = new Rectangle( array.GetAsNumber(0).FloatValue, array.GetAsNumber(1).FloatValue, array.GetAsNumber(2).FloatValue, array.GetAsNumber(3).FloatValue); rect.Normalize(); // A Do operator is forbidden inside a text block if (inText && !btWrite) { LOGGER.Debug("Introducing extra ET"); byte[] bytes = Encoding.ASCII.GetBytes("ET\n"); baos.Write(bytes, 0, bytes.Length); etExtra = true; } // Writing the marked-content sequence with the Do operator // Note that the position assumes that the CTM wasn't changed in the graphics state // TODO: do the math if the CTM did change! ByteBuffer buf = new ByteBuffer(); buf.Append("/P <</MCID "); buf.Append(mcid); buf.Append(">> BDC\n"); buf.Append("q 1 0 0 1 "); buf.Append(rect.Left.ToString(CultureInfo.InvariantCulture)); buf.Append(" "); buf.Append(rect.Bottom.ToString(CultureInfo.InvariantCulture)); buf.Append(" cm "); buf.Append(xobj.GetBytes()); buf.Append(" Do Q\n"); buf.Append("EMC\n"); buf.Flush(); buf.WriteTo(baos); // if we were inside a text block, we've introduced an ET, so we'll need to write a BT if (inText) { btWrite = true; } }