Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Content Count

  • Joined

  • Last visited

  • Days Won


2Explosions last won the day on April 17

2Explosions had the most liked content!

Community Reputation

1 Neutral

About 2Explosions

  • Rank
  1. 2Explosions

    Linq.Expressions for packet serializing

    @Spirited Sup! thanks for the interest, i like how nice is to use this board, kinda miss C2PvP tho. Still exploring alternatives, got a bunch of material to read so i will keep exploring, the code posted is pretty much the prototype that i got working, while it works, it is reaaaally unintuitive to use, after all, it is just a property iterator, and converting it (or maybe using it) for a complete serializer may become a big enough problem to deviate me from my actual project, most likely will code a Conquer specific serializer As said before (iirc, lazy to read, in other forum 🙄), my current goal is a flexible and scalable project, flexibility as main priority, and is quite a complex conquer project for me, i will keep itclosed source at least on early stages to avoid influence of more experienced programmers, failing would at least teach me what avoid in future projects. The project is experimental anyways, trying some C# features i haven't used for class implementations, some popular libraries, trying to get used with TDD approach (altough i'm not interested enough to use it during the whole project), also, i'm doing benchmarks and documenting why i'm using X approach, so expect at least a few threads like this one but better structured exploring possible implementations for not so useful things
  2. Started a CO server emulator to spend time (internet down for ~3 weeks here, limited bandwidth on phone) and noticed how painful is to de/serialize packets in pretty much any open source emulator... well, i always thought that tbh., even in my previous projects. So, as an excuse to learn a bit of System.Linq.Expressions, wich wasn't that hard as i thought, tried to avoid what the whole de/serialization code writing is. Keep in mind that this is still prototype code and before taking it any further, opinions would be be appreciated. The code is based on two Type's properties iterator (tried to keep the code generic), the first one to access to the properties and the second to assign the values to the properties. TypeIterator class: IterableAttribute class: Usage: PacketSerializer class PacketFieldAttribute class SerializationMethods class, this one exposes what will happen to every property depending of it's type and attribute Example with MsgAccount packet Output of console is the expected. Important things to notice: Packet class is just a BinaryWriter like class, you can see a similar one in a lot of CO related projects There are errors in SerializationMethods class, check strings for example Type alias are needed for generic types or arrays, the expression will search for ReadXX where XX is the type name, that is why the StringList alas is used for example. cya!
  3. 2Explosions

    Unexpectedly fast asynchronous calls

    @Spirited Yup, i opened an issue on the 6 yo. GitHub explaining it as a race condition, just that i didn't expect that one to happen, nice to keep it in mind for future projects.
  4. Thought someone here would find interesting this. Today, i moved CptSky's CO2_CORE_DLL to a .net core project, awesome library btw., to avoid coding the socket system and other things in an experimental source. So, for testing purposes, quickly added the OnConnect, OnReceive and OnDisconnect methods that the library offers to use. private void OnConnect(NetworkClient client) { Console.WriteLine("Accepted"); client.Owner = new LoginClient(client); } private void OnReceive(NetworkClient client, byte[] buffer) { Console.WriteLine("OnReceive"); var owner = client.Owner as LoginClient; client.Owner.cipher.Decrypt(ref buffer); Net.Packets.MsgAccount msg = new Net.Packets.MsgAccount(buffer); } nothing complex, but then, i started to test the RC5 class to decrypt the password in the MsgAccount class, quickly tried to "login", when i get an NullReferenceException at the second line of the OnReceive method, and client.Owner was null effectively, tried this few more times, and faced the same exception after around 5 login attempts, then i noticed in console the text OnReceive OnConnect The OnReceive method was being invoked before the OnConnect, eventually found this code in the ServerSocket class NetworkClient Client = new NetworkClient(); if (!Client.Create(this, Socket, Kernel.MAX_BUFFER_SIZE)) { try { Socket.Close(); } catch { Accept(); return; } } if (OnConnect != null) OnConnect(Client); and the NetworkClient Create method public Boolean Create(ServerSocket Server, Socket Socket, Int32 BufferSize) { if (Alive || Socket == null || Server == null || BufferSize == 0) return false; Sock = Socket; Serv = Server; Buffer = new Byte[BufferSize]; BeginReceive(); Alive = true; return true; } For some reason, the if(OnConnect != null) OnConnect(Client); was being executed after the BeginReceive ended (including it's EndReceive call), so now, i edited it to call BeginReceive after the condition instead of calling it during the Create method. Then, a bug that didn't happen in a while and i ignored at first, happened again, the OnConnect was invoked succesfully, but the client hanged there and no OnReceive call, the problem was the Alive = true; being executed after the BeginReceive, wich again, finished before the next operation in the method was executed. PD. The order was inverse, second error was repaired first, putting Alive = true; before the BeginReceive call.

Important Information

By using this site, you agree to our Terms of Use.