Networking in C++ Part #3: MMO Client/Server Framework, Tweaks & Client Validation

  Рет қаралды 60,332

javidx9

javidx9

Күн бұрын

In this video, I examine two major shortcomings of the networking framework, its CPU load, and its inability to distinguish friendly clients from nefarious ones.
Source: github.com/OneLoneCoder/Javid...
Patreon: / javidx9
KZbin: / javidx9
/ javidx9extra
Discord: / discord
Twitter: / javidx9
Twitch: / javidx9
GitHub: www.github.com/onelonecoder
Homepage: www.onelonecoder.com

Пікірлер: 174
@javidx9
@javidx9 3 жыл бұрын
Hello! I'd be really interested in seeing your alternatives for uint64_t scramble(uint64_t nInput) as used in the context of the video! KZbin Comment Coding FTW!
@derzweig205
@derzweig205 3 жыл бұрын
I wouldn't bother because it's just useless work that eats server resources. What you really care about at this point is that both can claim knowledge about the same protocol, just so to have the connection open for a bit longer. So for tat reason a bit of plain text like "olc 1.1" is much better. You can check that its olc and not http or random junk. Furthermore 1.1 can be checked for an existing version etc. Again its just there to establish both speak a common language. Once that is done (or not), you can move on to some form of actual encryption / authentication in order to prevent session theft, and or ensure that the user is really the one that it claims to be.
@lukeb8349
@lukeb8349 3 жыл бұрын
I don't see how scramble is a secure method for client validation. Since we're building native code here, can't an attacker just decompile the binaries and figure out what's going on inside this method? If our threat model is that we're assuming a user won't do this, then the safest option might just be to include a server certificate with the game binaries and have the server/client perform public-key cryptography (the server sends a random value, the client encrypts the hash using the public key and well-known secure hashing algorithms, and the server verifies its private key decrypts the hash to the sent value). I was taught that when it comes to cryptography, don't ever even attempt to write a secure method. It almost never is cryptographically secure, and we should be using a well-known algorithm that experts design. So in this case I'd argue exposing the method used (or at least not making an effort to obfuscate it) and just hiding the public key is the right move. The benefit of this is also that you can rev the sever version just by making a new certificate to include in new releases.
@unicycle332
@unicycle332 3 жыл бұрын
A good alternative would be an HMAC function that uses a secure hash function like HMAC-SHA256 for example. An HMAC function takes two arguments "Message" and "Key". In this case you would put random data into "Message" and then use some secret data which could also contain the version number into "Key". You will get an output of a fixed length (256 bits for SHA256). You can use it in the same way as your scramble function by computing the HMAC on both the client and the server after sharing the random data and then comparing the results. It is extremely difficult to figure out the HMAC key from the message. I think this method is better than the current scramble implementation because well known hash functions have been tested and proven to stand up to attack. The current scramble function is what's known as "rolling your own crypto" and is highly disadvised. There are still many security issues with this approach and this method cannot be relied upon on it's own. For example an attacker could create lots of connections to use up server CPU resources computing the HMAC and this method doesnt protect the connection of a valid client after the handshake has finished. Basically this will still not ensure a secure connection but that's ok for a tutorial.
@gideonmaxmerling204
@gideonmaxmerling204 3 жыл бұрын
well, I wouldn't have that function, any attacker can just "fish" the function out of your binaries, what you should do is make a header validation function, if the header is invalid (length is too long or the message type is outside the bounds) then just throw it out
@OneMeanDragon
@OneMeanDragon 3 жыл бұрын
if you go the way of battlenet-1, theres a few blocks. initial single byte = connection type, if that validates, client follows up with a game version check request, which could require another connection to the server (connection type ftp) for a dll to be downloaded to validate the client executable and cdkey if it used one, if you pass that, your to follow up with either account create or account login, if you create you follow up with login, if login passed your effectively on the server, at the server chat level in a channel based on your provided language. all their games during that time except 1, used a broken sha1, and the other used srp-3. rather simple and effective compaired to what their newer games run on lol.
@gamesilo7515
@gamesilo7515 3 жыл бұрын
I honestly don't know how i discovered this channel now ? How could i miss it this whole time ? This is pure gem. Thank you sir.
@javidx9
@javidx9 3 жыл бұрын
Cheers buddy!
@QuickNETTech
@QuickNETTech 3 жыл бұрын
I found it because of "Forbidden C++", stuck around, watched a lot of the back content and the watched most of what's come after.
@Salehalanazi-7
@Salehalanazi-7 3 жыл бұрын
Reminder that he has a Patreon
@scriptercoding
@scriptercoding 3 жыл бұрын
OLC, make a video showing how do a radial gradient effect in a plane, :D It's an almost general effect in games
@danbopes6699
@danbopes6699 3 жыл бұрын
I think it would have been awesome if you mentioned that this handshake is also a good way to prevent against DDoS attacks. A lot of server apps now take advantage of cryptographic functions to prevent against DDoS attacks, by having the client do a fairly process intensive task (Like sit in a tight loop, processing hashes), that is extremely simple for the server to validate (Essentially what crypto-chains use). ie. Provide the client with an initial seed # (serverSeed) randomly generated, and a complexity #. Next, the client takes the initial seed #, and begins to process thousands of hashes (Which entirely depends on the complexity #): The client starts a loop: for (var i = 0; i < int32.MaxValue; i++) { var result = sha256(initialSeed + "|" + clientInt) // Next we look at the number of zeros that the seed starts with if (result.substring(0, complexityNumber) == "00000...complexityNumber") { //We found a sha seed that starts with the number of 0's required in order to authenticate completeHandshake(clientInt); // Pass this clientInt back to the server } } The server then can really simply calculate one SHA256 hash: sha256(initialSeed + "|" + clientInt) // If the hash generated here, meets the complexity, allow the connection, otherwise simply discard it/block the connection. The client then does a tremendous amount of work to connect, thus stopping the server from wasting a ton of resources on processing connections. A quite ingenious way: If the client takes 200ms to generate this seed, for someone to DDoS, 200ms is an absolute nightmare, which will overwhelm their systems before they can do any damage to yours.
@contentnation6108
@contentnation6108 3 жыл бұрын
I think the scambling function as a stub for a connection handhake is fine for a tutorial series. But nothing that should be used in production. You never ever should rely on security by obscurity ("secret code" that is in the client application). Better would be an open protocol with good cryptographic authentication (like per user unique username/password over tls), but this would be too advanced for a tutorial like this. So make a remark, leave it in and go on ;)
@Dave_thenerd
@Dave_thenerd 3 жыл бұрын
5:47 It's worth mentioning that if you're developing for Windows there is a Windows Kernel specific Condition Variable type and Memory Barrier type which in combination both prevent spontaneous wake up and dead lock (in this scenario). std::condition_variable is not 100% guaranteed and std::memory_barrier [in C++ 20] are both generalizations and don't have real kernel-based implantations (Windows and IBM's Zos are the only OSs which have memory barriers in the kernel at the moment) so they will not prevent spontaneous wake up or dead lock 100% of the time but like 90% of the time) An adaptor pattern with Windows specific code would make this a super stable server.
@robinsonlew4467
@robinsonlew4467 2 жыл бұрын
Although each video is less than an hour, it makes me half a day to consume it. I'm sure the time you spend on each video must be more than several days. Thank you very much javid!
@williamokano
@williamokano 3 жыл бұрын
You can't imagine how anxious I was waiting for this part 3 😂. Waiting for the MMO implementation and furthur tweaks
@JoshRosario310
@JoshRosario310 3 жыл бұрын
Epoch caught me off guard 🤘
@germandiago2193
@germandiago2193 3 жыл бұрын
Go ahead javidx9. You are the single best ever person I have seen at explaining non-trivial programming topics.
@XYZ-bz8tf
@XYZ-bz8tf 3 жыл бұрын
Dude..he fundamentally teaches the most important concepts.
@mohammade.8770
@mohammade.8770 3 жыл бұрын
The Legend strikes again ♥️♥️♥️
@douggale5962
@douggale5962 3 жыл бұрын
I almost suggested using an asymmetric public key algorithm to exchange keys and become immune to man in the middle attacks - then I realised, the attacker has complete control over the client, they can do their hacks before the encryption and defeat that as cheat prevention. Anti-cheat must be done primarily on the server, where attackers have no control over it.
@javidx9
@javidx9 3 жыл бұрын
Correct Doug, the server will need to look for "impossible" situations, such as player movement speeds etc
@onogrirwin
@onogrirwin Жыл бұрын
best video on the internet so far this epoch.
@zuhail339
@zuhail339 3 жыл бұрын
My go-to for C++ ♥️
@VmsCentral
@VmsCentral 3 жыл бұрын
@javidx9 25:30 forward declaration is unable here according to used method OnClientValidated of server_interface at 23:27 of video. Yes, one of project can use only forward declaration but second required including of header with server_interface class.
@user-tz5bz4cz9q
@user-tz5bz4cz9q 3 жыл бұрын
Thanks sir Javid! Cool videolesson!
@drew21t
@drew21t 3 жыл бұрын
Guys you've got to realize that this is a simple approach to client validation and isn't by any means what you should use. He's, like always giving you something you can work with. If you're looking for actual approaches to doing proper client validation, you want to look at implementing a login process using some sort of key system with a database like any other authentication process in application development does. Keep in mind that there isn't a single mmo out there that you don't type in some sort of authentication credential into before logging in to the game. His process is just a good starter for you to look at expanding upon. I assume so that he doesn't have to host the infrastructure to do proper authentication etc, which I feel because who wants to host more than they have to.
@_syedmx86
@_syedmx86 3 жыл бұрын
"Bonjour" "Yo" Very nice
@manas_singh
@manas_singh 3 жыл бұрын
I had been waiting so long
@eriktarnok391
@eriktarnok391 3 жыл бұрын
I am into creating operating systems. Everyone has their own favorite thing.
@jphvnet
@jphvnet 3 жыл бұрын
Hahaha
@mansirrabiu7412
@mansirrabiu7412 3 жыл бұрын
You must be a genius 👍
@eloquentlyemma
@eloquentlyemma 3 жыл бұрын
I can relate to that:-) May I recommend Fundamentals of Operating Systems by Lister and Eager. I don’t know about later versions but the one we used in College - early 90s as really interesting and taught me so much.
@eriktarnok391
@eriktarnok391 3 жыл бұрын
@@eloquentlyemma Thank you very much.
@billybest5276
@billybest5276 3 жыл бұрын
From the EPOCH till the break of dawn and so on ...∞
@traxooza
@traxooza 3 жыл бұрын
Hi Javid, In the git repository of this project, you were mentionning that there is a memory leak. I can not figure where it is, any ideas ? Thanks
@maksimsivyy5684
@maksimsivyy5684 3 жыл бұрын
Hello, great video! Here is my thought => when some thread calls tsqueue::wait, it might be locked forever(rare case, but what if there is empty queue and we want to close our program), so, is it a good idea to add some bool flag to 'wait' loop + one "wakeup" function to tsqueue(which just sets 'stop' bool flag and calls cvar.notify_all to notify and unblock all threads when we don't want to wait anymore)? This approach seems to be "ill-formed", but how can we finish our app properly while some thread is blocked at tsqueue::wait? Also, in my code instead of using 'update' mechanism, I use default callback for every incoming message, provided by io_context::strand to execute these callbacks consistently.
@mukeshv5522
@mukeshv5522 3 жыл бұрын
Your videos are awesome!!!can u make a series on writing Joystick emulators?
@erikpavlusik6214
@erikpavlusik6214 3 жыл бұрын
Thank you
@videobros6556
@videobros6556 3 жыл бұрын
Love your videos keep it up!
@whoisheiforgothisname2103
@whoisheiforgothisname2103 3 жыл бұрын
I don't know what your saying but I like your words magic man.
@billybest5276
@billybest5276 3 жыл бұрын
Amazing as always.
@tmbarral664
@tmbarral664 3 жыл бұрын
@javidx9 just a thought: it may be worth to allow the user to provide his own implementation of scramble, don't you think ?
@r1pfake521
@r1pfake521 3 жыл бұрын
Nice to see how validation could be implemented, but honestly I think for this kind of project a simple header validation (check for valid id and a max message size) would be good enough, since the current validation logic can be easily "hacked" anways. These simple pre filters (id and size) would already disconnect many random connects and the ones who sent a corret header, but "invalid" data (by accident or purpose) must be filtered out later anyways, because the server has to validate everything the client sends to it. For example if the client sends a "UseItemRequest" message with invalid data (for example an item id that doesn't exist), then the server has to detect the invalid message anyways, no matter if it was sent by a client, random connect or hacker.
@ratchet1freak
@ratchet1freak 3 жыл бұрын
your condition variable use is wrong, no need for the second mutex and the in the wait() the unique_lock (of the original mutex) should be moved to outside the while loop. Otherwise if you get preempted right after the empty call and before locking the blocking mutex and another thread does a push you can still be stuck in the wait without getting woken. You can also pass a lambda to make the while loop proper: cvBlocking.wait(muxQueue, [&](){return !empty();}); this will handle the loop for you and will wait until the predicate returns true.
@PetrPss
@PetrPss 3 жыл бұрын
Yes! I made comment saying this to previous video month ago. Looks like it got ignored.
@FreeDomSy-nk9ue
@FreeDomSy-nk9ue 3 жыл бұрын
Hey, Do you have an idea about how long this series will be? How many parts exactly. coincidentally, I am trying to learn client-server communication (using cpr framework and I feel comfortable with it), but your videos keep coming out and they're really interesting, making me ambitious about learning ASIO.
@javidx9
@javidx9 3 жыл бұрын
I suspect (given my schedule) that there will be two more parts showing how the game is implemented using this framework, though the network nitty gritty is done with now.
@sqw33k
@sqw33k Жыл бұрын
6:36 Can someone please explain to me why we are locking using muxBlocking here? Isn't this already locked by the wait() function resulting in a deadlock?
@nikkiofthevalley
@nikkiofthevalley 2 жыл бұрын
I've been having an issue. For some reason, the code in part 2 doesn't work properly. It only lets me send 1 ping message, and it takes a few tries to get it to send anything but garbage data, and the resulting time is something like 2 centuries. I even resorted to copy/pasting code, just to see if I missed something, but no, it still doesn't work properly. (The other message types don't work either, it's the same with the ping)
@misterhat5823
@misterhat5823 3 жыл бұрын
Why not check the size of data before allocating memory? If sent a data size in the header that is bigger than expected, close the connection instead of allocating the memory.
@thehambone1454
@thehambone1454 Жыл бұрын
Would it be fairly easy to convert this to UDP? Will there be UDP tutorials in the future? Thanks for making these.
@Ownage4lif31
@Ownage4lif31 3 жыл бұрын
What about have a user/pass system that connects to a DB. Let's you in if authorized, else kicks you out. But I do believe most games usually have a token generated by the lobby/client that is used for the socket to identify the player. By no means do I know what I'm talking about. Just a few guesses here and there.
@elvrathstat9653
@elvrathstat9653 3 жыл бұрын
Hello javidx9 I have a question: On Silicon Valley tv show they make an app where they are able to convert large files into smaller files so that way they have access to accumulate more data. Can we make something like that and if so how would we call it so I could find a course that does that?
@javidx9
@javidx9 3 жыл бұрын
This is called compression. A good place to start would be Huffman Encoding, and if you really want to study it, you'll need a course on information theory.
@mad_t
@mad_t 2 жыл бұрын
omg you scared the crap out of me with that EPOCH.................. :)
@davidecalaminici2937
@davidecalaminici2937 3 жыл бұрын
Hello, there's a way to contact you about the convex polygon collision code or for some other informations? Maybe you don't receive comment notifications on old video.
@javidx9
@javidx9 3 жыл бұрын
Easiest way is via the discord server!
@mercygotnerfed315
@mercygotnerfed315 Жыл бұрын
Ill you talk about linked-list more in derth ? I just love the way you explain code
@myroslavaahafonova3875
@myroslavaahafonova3875 3 жыл бұрын
Hi! Thanks a lot! Please tell me can I enter the number of port by myself from a simple string(cin>>port;)?
@nikkiofthevalley
@nikkiofthevalley 2 жыл бұрын
??? You enter a port number, an int, not a string.. Also, I'm guessing English isn't your native language by the really off grammar..
@centis4533
@centis4533 2 жыл бұрын
Hi, Could you please help me, How to construct a TCP Protocol with 3 arguements? I have the "IP Address", "Port", & "An integer" as third arguement for indentification of the cconnection.
@javidx9
@javidx9 2 жыл бұрын
The third is a pass by reference argument, ie it will be populated by the function. In the case of asio, it's an error code, so you can examine it to see how the attempt to connect performs.
@AI-ec2qb
@AI-ec2qb 3 жыл бұрын
You are a Top Notch programmer
@kane1356
@kane1356 3 жыл бұрын
Thanks handsome bearded C++ wizard!
@eriktarnok391
@eriktarnok391 3 жыл бұрын
Its cool! 😎
@metalhead3ecr
@metalhead3ecr Жыл бұрын
In the same way you fixed the Server CPU consumption, can we apply that same method to the clients so they don't use a full CPU core?
@metalhead3ecr
@metalhead3ecr Жыл бұрын
nevermind, got it working. Thanks for the great tutorial series!
@walidjabari4985
@walidjabari4985 3 жыл бұрын
what's wrong with basic http authentification or public/private key pair for your use-case ?
@VmsCentral
@VmsCentral 3 жыл бұрын
@Walid Jabari At first probably not tutorial friendly approaches. Second - may not enough rate for game purpose.
@kevinkouketsu3952
@kevinkouketsu3952 3 жыл бұрын
Can you provide the source code? It's been two months since this video. Thanks. Amazing serie! Please, continue doing this amazing job.
@sirius-light
@sirius-light Жыл бұрын
If the library that implements connection class and all logic is shared between server and client that means client will have this library on his hard drive after he download the client, in this case this library can be decompiled and all handshake logic can be easily analysed and used to hack our server, Am I right or no?
@goldenlava1019
@goldenlava1019 3 жыл бұрын
Soooo we are using TCP sockets, but the goal is to make a game with this. From what I know (I don't know very much) TCP sockets are good for sending chat messages or other messages that you need to get there in the same order, but if I need to send the players position to the server every frame then I don't care if some of them don't get there, the server just needs the current players position. That's what you would use UDP sockets for. So I'm just wondering if we are going to add UDP sockets to the framework, or if we are just going to make a game that doesn't need to send a lot of data to the server every frame.
@drew21t
@drew21t 3 жыл бұрын
The idea is that he established a framework that can use pretty much any type of connection up to the user. So what you want to do is go back to the first video when he was declaring the connection type and create a second one for UDP and then adjust accordingly to support it. And MMO's don't just use UDP they use both a TCP and UDP connection in general. Most of the time you actually have two connections to the game world not just one. UDP is used to send stuff that can get lost like you said, world position, and TCP for really critical things like, for instance, headshots hits or damage calculations that should end processes for other players etc. At that point it really comes down to how your game functions, is it a fast paced FPS then you're probably going to be sending a lot of TCP messages, but for something like chess or a role playing game, you can get away with UDP messages. The point is the framework allows for either type to be sent.
@PolarisMyWay
@PolarisMyWay 3 жыл бұрын
Hej, what about adding encryption SSL/TLS?
@blumenkohltv1565
@blumenkohltv1565 3 жыл бұрын
So hyped ^.^
@wjrasmussen666
@wjrasmussen666 3 жыл бұрын
Nice.
@Hawkadium
@Hawkadium 3 жыл бұрын
"Erroneous WakeUp" also known as the NSA checking in on you.
@blumenkohltv1565
@blumenkohltv1565 3 жыл бұрын
I don't see how the scramble is more useful then just sending some data and letting the client add some secret to it and then hash it. I mean if the "attacker" actually has a client he can just edit packet sizes after validation. If its just about blocking random attacks anything that isn't just a static response (that then could be part of a list for bruteforcing) should be equal, or am I missing something? I think there is no way to make anything than can be used in public with client packet sizes, but if I understood you correctly you intend not to do that with the mmo :)
@xBZZZZyt
@xBZZZZyt 2 жыл бұрын
What if client sends garbage after being successfully validated?
@Froggysrevenge
@Froggysrevenge 3 жыл бұрын
I'm probably not contributing much, but according to the cryptography class I took in college, a good cryptographic function can be known. Things like RSA are public knowledge, but they're still secure because as long as you don't know what the key is, you can't get in, even if you know how the lock is built. Assuming nobody will reverse engineer your code is security through obscurity, or not secure at all. It's probably fine for a game, but with things like passwords and sensitive information, trusting nobody to reverse engineer your stuff isn't smart.
@zergon321
@zergon321 3 жыл бұрын
What do you think of Go programming language?
@javidx9
@javidx9 3 жыл бұрын
I have no opinion of it.
@nazzak2093
@nazzak2093 2 жыл бұрын
You scared me with THE EPOCH dude
@INeedAttentionEXE
@INeedAttentionEXE 3 жыл бұрын
Arguably, another computer from across the world can call malloc() on your computer allocating gigabytes of space, I just find that absolutely fascinating.
@clumbo1567
@clumbo1567 3 жыл бұрын
Some DTLS encryption would be good
@FalcoGer
@FalcoGer 3 жыл бұрын
your scramble could simply be AES encrypt with a hardcoded key. AES has hardware implementations for 128bit keys on most architectures, so it should be fairly fast, too. and you can be sure that people are not going to find out your key by looking at the traffic in the near future. of course they would find out your key if you post it on github :P of course the initial message from the server could very well include the version number, too, even in clear text. Of course you could just encrypt the whole session, but if you go that route you might as well do the whole key exchange thing and use tls1.3. www.cryptopp.com/wiki/Advanced_Encryption_Standard
@RealNekoGamer
@RealNekoGamer 3 жыл бұрын
Wait, I thought mutexes (mutices?) guard the whole data structure? Like muxQueue would guard not just deqQueue, but also cvBlocking. I've never seen any mutex assigned an association to a variable. I thought it just guarded the whole scope. This validation reminds me of the now-very insecure Hotline Connect protocol. It had a header/body system all the same, but upon connecting, the client sends "TRTPHOTL\0\1\0\2" to which the server replies with "TRTP" and a 4 byte error code, usually 0.
@davidreynolds9649
@davidreynolds9649 3 жыл бұрын
Could this be the basis for a real online MMO of thousands (10-25k) of players each making thousands of requests? I guess I'm asking if it is scalable or is it best to start elsewhere!
@dempa3
@dempa3 3 жыл бұрын
I'd be really interested in more videos on proceduraly generated content and especially on how to "save" the users interactions with the proceduraly generated content. And to go even further it would be very interesting to know if one could proceduraly generate agents, besides the user, who interact with each other and the rest of the content independently of the user, as well as with the user.
@KC-vq2ot
@KC-vq2ot 3 жыл бұрын
Javid, more of a philosophical question about dependencies At what point bringing a new one in can be justified? I try avoiding having more dependencies then absolutelly necessary In certain places I end up rewriting ton of code from scratch If you put it all together, I probably wrote half of Boost by myself I am not some fundamentalist who would write his own OS implementation only to have no external dependencies If complexity is not really worth it or I need really big chunk of library and it is just dumb to, basically, remake an existing lib, why would I do that? Also, for some dummy functionality where I need working it now and either don't really care about how or replace it soon enough What bugs the hell out of me Is people adding a new dependency only to use a couple of semi-trivial features that would take only a couple hours or a day to reimplement from scratch. Langs like Python are the biggest offenders as dependencies have their own dependancies and you might end up installing Anaconda to read excel data Not to mention that some libs (even widely accepted) are badly designed, poorly maintained, rely on some guy in a middle of Siberia not dying during bear hunt or all of the above and you just add a ticking time bomb to the project. What is your take on that? I know that you use a lot of external libs in your tutorials, but they are home projects that are not meant to take a lot of time, be simple and you don't really care about lib existing because your interest clearly won't outlast the lib. Even I don't write my own code for that, unless there are some bad offenders like string.h C library (I rewrote a lot of C standard library because it is clearly a product of it's time) or libPNG
@xriccardo1831
@xriccardo1831 3 жыл бұрын
Yes
@MissNorington
@MissNorington 3 жыл бұрын
'if (m_nOwnerType == owner::server)' code is linked into the client? Make it a template argument so it only gets linked with the server. Clients shouldn't see that code from a debugger.
@NinjaNJH
@NinjaNJH 3 жыл бұрын
Nobody: olc : DEADBEEFC0DECAFE
@mr.awesome5109
@mr.awesome5109 3 жыл бұрын
When do you think the series will be finished? Like what number in the series? Just curious.
@MassiveBreaker
@MassiveBreaker 3 жыл бұрын
EPOCH
@alecs2056
@alecs2056 3 жыл бұрын
Whats stopping me to just decompile the client and extract the function that does the scrumble? I don't need to understand the function I cant treat it an a blackbox
@javidx9
@javidx9 3 жыл бұрын
Nothing at all. In principle you would need to move to secure communications protocols to have anything realistically capable of preventing all attacks. My approach is more of a nuisance prevention.
@xeridea
@xeridea 2 жыл бұрын
So, I can just wait for client to validate, then send junk and crash server..... You still should do checks on each requests. Simple things like capping body size to something reasonable. Also, server could send version, as well as challenge upon connection so client can notify user what version is needed.
@traxooza
@traxooza 3 жыл бұрын
19:41 you could also use std::radom_device to generate an arbitrarly-long random data for users that would like to rely on longer-sized validations
@valuial_
@valuial_ 3 жыл бұрын
I don't think "more random" data would improve this validation. Since it is not the data that is the secret - even being able to predict the random data doesn't gain you anything. The "secret" here is the scramble function. One might even suggest using ms since EPOCH is a good choice since you guarantee no repeat of the same challenge being sent.
@danny-jo1rb
@danny-jo1rb Жыл бұрын
the E P O C H
@mursitkc5328
@mursitkc5328 3 жыл бұрын
Source?
@streetfashiontv9149
@streetfashiontv9149 3 жыл бұрын
Hi Javid, i love your videos bro they help me alot especially the ones about gaming. Its slightly off subject but i am trying to make a card game with an image array that holds the cards. I am stuck on this. Do you know how to create an image array in Java that iterates through images in a file? cheers
@tz4601
@tz4601 3 жыл бұрын
What you would rather want is a Card data type. This custom data type would hold information such as suit and value. Separately, you would want to have some sort of data structure to hold resources -- in this case, pictures representing your cards. Each of your cards could then have a pointer to whichever image represents it. One of the big sticking points for me when I was starting to learn programming was understanding that I needed to think about data separate from display. Logic deals with data. When we need to display something, we write some system that matches up data with its appropriate visual representation (whether that's a simple image or a full 3D game renderer). This is a split you'll see all throughout programming; for instance, in the web space we have the pattern Model View Controller. As to loading the images, I don't know what libraries to use specifically in Java, but what you would want is to store one image per file. Then you would use an appropriate Java library to load each image one at a time into a resources structure (which could just be an array). In general, code is not smart enough to be able to look at a file containing lots of images and just somehow know how to split them up into their individual component images. 2D games use something called sprite sheets, so if you are able to find a Java game programming library you could look into those as well. Sprite sheets contain lots of images in one file, but they are placed in a precise rectangular grid so the code knows how to split them up.
@user-cb6bn5iv2s
@user-cb6bn5iv2s 3 жыл бұрын
You know game Dwarf Fortress? Could you please explain how dwarvies AI works in game Dwarf Fortress? From proger view ofcourse.
@gokusaiyan1128
@gokusaiyan1128 3 жыл бұрын
Hey do you mind if I create a blog series based on your videos ( basically referencing it and then making my own ) ?
@markiel55
@markiel55 2 жыл бұрын
"Epoch" 19:39
@misterhat5823
@misterhat5823 3 жыл бұрын
For the scramble data function: Take the sent data and append some known string (possibly the version number) and compute a hash (such as MD5.) Even though MD5 isn't considered secure anymore, I suspect it good enough. If not, there's other hashing functions. For added fun scramble the string before hashing it.
@eriktarnok391
@eriktarnok391 3 жыл бұрын
👋
@catapillie
@catapillie 2 жыл бұрын
french be like - bonjour. - yo
3 жыл бұрын
You adressed one problem by solving a completely different problem... While authenticate the client is an important problem to solve, it does nothing to actually solve the problem that the consistency of the message header is not protected. The header should include some sort of redundancy field, like a checksum or a crc that guarantee that the header is consistant before trying to use any information from it. Also the read message function need to put a reasonable max size on the length, a full 32-bit length field implies you could be trying to read 4 GB from the client, wich doesn't seem necessary.
@danbopes6699
@danbopes6699 3 жыл бұрын
I really disagree with your plan to "accept something I'd expect" when you connect. It's quite easy to mimic that by looking at how the client connects, and then specify the max size for integer, to allocate a large amount of memory, and crash your program. It would have been lightyears simpler to limit the size that can be allocated to a reasonable size. Anything over that, simply reject and disconnect the client.
@javidx9
@javidx9 3 жыл бұрын
It wouldnt crash anything - the server only reads first 8 bytes of validation. If its incorrect everything else is shut down. I also describe exactly what you argue in the video - about using predefined structures, and just a structure ID to discriminate - and go on to say this is how it will be implemented after we have finished the development of the game, as at this stage the flexibility is more useful than the constraint while developing.
@danbopes6699
@danbopes6699 3 жыл бұрын
@@javidx9 Yes: So your server reads first 8 bytes of validation. A hacker modifies the client, and reads how you connect to the client. (Even complex code, such as WoW and many other MMORPG's, with the use of Ghidra or other decompiler software, can figure out how the handshake is done). Once the handshake is done: The hacked client can then go on to request insane amounts of memory, in a tight loop, to fill your entire process. Predefined structures (With limits in place) would help, but in this instance, setting a simple lower memory limit (Maybe like 1mb for a packet, or 65k) would have been a better solution.
@delqyrus2619
@delqyrus2619 3 жыл бұрын
I wish you would take care about stuff like "hole punching"(STUN, etc.). Having a server, that handles every single player, might be very expensive for tiny projects. Having some server-independent communication between clients might be helpful, so you server only needs to tell the clients, where to send their packets. Also it might reduce the delay between actions.
@eidodk
@eidodk 3 жыл бұрын
That would expose the clients to eachother. That's not really an option. If you want to make a "secure" game, you have to control the communication, which you can't if you bypass the server validation and anonymisation of the messages. Also - using UDP to communicate is bad, since there's zero data control.
@delqyrus2619
@delqyrus2619 3 жыл бұрын
@@eidodk nah, you give them your ip - that isn't something really unusual - actualy every ip in the world is somehow public. Security isn't made by obscurity - it is made by the system. of course, you may not want people to know you ip. but you usually don't play with strangers - and in the most tasks, you somehow expose your ip to your friends.(webrtc, which most of the usual communication systems use, does actually the same thing.) Of course - if you create some sort of mmo, this is an issue. But there you have much more interesting issues to call, than the protection of the client ip. In these cases there actually is no way around of a central server.
@eidodk
@eidodk 3 жыл бұрын
@@delqyrus2619 I don't know ANY network game, that exposes the players IP's, it would be REALLY unusual, and would expose any player to DDOS attacks.
@r1pfake521
@r1pfake521 3 жыл бұрын
I also don't know any network game that exposes the player IPs to other players, in the EU you already have to be careful to not even log player IPs on the server, they would crush you if you sent the IPs to other players lol
@delqyrus2619
@delqyrus2619 3 жыл бұрын
@@r1pfake521 Okay, take any game, that doesn't work with a central server. Like Stardew Valley, Don't Starve Together and so on.
@thatsnuts8935
@thatsnuts8935 3 жыл бұрын
nothing just wanna refresh the scrap book
@tautvydassiuksta7698
@tautvydassiuksta7698 3 жыл бұрын
Make c++ tutorials
@coinconclusive
@coinconclusive 3 жыл бұрын
:D
@Digidan5
@Digidan5 3 жыл бұрын
first
@Digidan5
@Digidan5 3 жыл бұрын
turns out this was a lie lol
@javidx9
@javidx9 3 жыл бұрын
smh...
@homomorphic
@homomorphic 3 жыл бұрын
18:01 the client for a game is under complete control of the attacker, they will simply decompile your client with ghidra and see exactly what the algorithm does.
@drew21t
@drew21t 3 жыл бұрын
which is why you would actually implement a database auth system where you actually use keys for authentication, but for a simple application framework this gives you something to build upon and ultimately augment.
@homomorphic
@homomorphic 3 жыл бұрын
@@drew21t how do keys help? You're trying to authenticate the client. If you put a private key in the client the attacker has it and can lift the key and use it in their own client.
@drew21t
@drew21t 3 жыл бұрын
@@homomorphic you do it as apart of the authentication process like you would for any other application. and you do it in combination with some sort of login credential. or you don't use a key at all and just use login credentials like most games do. the point is there are many approaches to authentication that are considered industry standards for proper access.
@drew21t
@drew21t 3 жыл бұрын
@@homomorphic and, if you do use a key, each key would be coupled with a login credential to ensure that is the user. thats just one way to go about it. basically a password.
@homomorphic
@homomorphic 3 жыл бұрын
@@drew21t this has nothing to do with user authentication. You are trying to authenticate that it is your code that is talking to your server. The attacker (a cheater in a game) is almost always in possession of valid user credentials. The only way you can accomplish authentication of the client code, is if you can guarantee that the the client code can be neither tampered with, nor observed, and that is a non trivial problem.
@user-ec6kt2fg7m
@user-ec6kt2fg7m 3 жыл бұрын
17:44 what is this new English word? is it xor?
@link8290
@link8290 3 жыл бұрын
Yes it’s XOR, or bitwise exclusive or. You can search it on google to get more information. Notably, it isn’t technically a word, but just a way to say the acronym for it
@adityadey9591
@adityadey9591 3 жыл бұрын
Please sir make a full tutorial on c++
@ayush.kumar.13907
@ayush.kumar.13907 3 жыл бұрын
EPOCH
Networking in C++ Part #4: MMO - Designing Passivity
38:59
javidx9
Рет қаралды 71 М.
She’s Giving Birth in Class…?
00:21
Alan Chikin Chow
Рет қаралды 4,6 МЛН
어른의 힘으로만 할 수 있는 버블티 마시는법
00:15
진영민yeongmin
Рет қаралды 8 МЛН
Networking in C++
32:50
The Cherno
Рет қаралды 221 М.
Super Fast Ray Casting in Tiled Worlds using DDA
30:03
javidx9
Рет қаралды 172 М.
BEST WAY to make Desktop Applications in C++
26:00
The Cherno
Рет қаралды 873 М.
Transport Layer Security (TLS) - Computerphile
15:33
Computerphile
Рет қаралды 467 М.
Hacking Websites with SQL Injection - Computerphile
8:59
Computerphile
Рет қаралды 2,4 МЛН
One Tool for Everything
17:16
Chris Titus Tech
Рет қаралды 672 М.
learn network programming in c, but without all those pesky sockets
8:52
Low Level Learning
Рет қаралды 91 М.
FASTER Ray Tracing with Multithreading // Ray Tracing series
22:23
iphone fold ? #spongebob #spongebobsquarepants
0:15
Si pamer 😏
Рет қаралды 201 М.
ПК с Авито за 3000р
0:58
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,5 МЛН