Networking in C++ Part #4: MMO - Designing Passivity
Vložit
- čas přidán 13. 02. 2021
- In this video I look at how we treat the client as a passive observer of the ongoing game simulation. Thinking in this manner trivialises the interactions required for the MMO game.
Source:github.com/OneLoneCoder/Javid...
Patreon: / javidx9
CZcams: / javidx9
/ javidx9extra
Discord: / discord
Twitter: / javidx9
Twitch: / javidx9
GitHub: www.github.com/onelonecoder
Homepage: www.onelonecoder.com - Věda a technologie
There’s something different about this entire channel, about you. I can’t quite enunciate it. Particularly, you went from unknown to number one go-to programming channel. Serious “clicks” happening after watching your videos. Thank you so much for taking time out of your life to create such wonderful content.
Thank you Welder, such a kind thing to say and certainly much appreciated! Im pleased things click for you, makes it all worth while!
Totally agree! Thanks a lot Javid!
It's because he covers popular topics and is an excellent teacher. Instead of teaching you how to abstract apples and oranges from a fruit class, he will use more practical examples that interest people. Plus, he has that accent which gives you that happy feeling of being narrated a storybook before bedtime.
He is awesome, and imo probably the best coder I've seen on CZcams but I wish he would make these kind of videos or even a separate series using more common frameworks and libraries rather than his olc library, that's a big reason why I don't watch very much any more. In reality most companies are going to ask for experience with well established frameworks and libraries. I mean don't get me wrong I think it's amazing that he wrote his own easy to use library that has little dependencies but as I mentioned companies won't be asking "have you got any experience using the one lone coders library". I wish he would use libraries,APIs and frameworks like opengl,SDL,windows.h,FLTK or even QT. A fan can dream though.
Hmmm. Those libraries require you actually know how to solve problems before you can use them. On their own they are useless. If all you see here is pixel game engine, and not the broader scopes, the data structures, the analysis, the algorithm theory, the general application of computer science to solving problems, then that's a shame. I take a fundamentally different approach to delivering those topics by quite deliberately not aligning with specific vendors, and empirically I'd say it's successful. People watch the stuff and port it to all sorts of platforms, framework's, languages and hardware, because the principles don't change regardless of the library used (or abused 😄)
Is video 5 still in the works?! This has been a wonderful series!
You are a great teacher Javid. I hope this series makes a comeback.
Fantastic video again @javidx9.
The time you spend condensing and articulating these complex topics is greatly appreciated. Looking forward to many more videos to come.
Absolutly fantastics 4 parts ! Thanks a lot ! Truly help me get the "intuition" and "concept" of it !
I love this series, I hope there's a lot more episodes to come for it, just the videos I've wanted for years
everytime you post it re-ignites my fire to watch while picking back up my project
New vid - new upvote. Your videos are just so good and easy to process.
Great video, as usual. Very nice explained... I missed your videos and this is a great comeback
Thanks for this Javid! You do such a good job of breaking giant software engineering topics up into bite-sized chunks and explaining them clearly for the masses. I hope that someday you're able to transition to doing coding training full-time, assuming that's something you'd even want to do, simply because you're so well-versed at it.
Thanks Phroggster - Id love to do YT full time, but its not possible since I dont run any ads... Will have to stay a hobby for now!
This is one of the best channels on CZcams !
finally part 4 .. thank you Javid :)
This series upto this video has taught me so much about network architecture and networking. Thanks so much! :D
Extremely helpful. Thank you for making these videos.
Nice! I've been waiting for this!
So happy to see you make it over 200k Subs Javid, you deserve it and more!
Thank you Tyson! Scary Stuff XD
This is so informative and lucid. Great job
Can't wait for the next episode ! It really is super interesting
I just found this tutorial and extrmly excited. awsome man
Very impressive how you can take such an intricate topic and make it feel so natural.
Will you address hacked client? And how to prevent them?
If the server is truely completely passive then it would be quite simple to teleport and so on.
Either way this is a fabulous introduction and I'm sure it will inspire many!
This can be presented with client prediction and server authorive movement, there's articles and videos that'll explain it much better than me
Hell ,and I'm here watching on 5am. Just wow
really enjoying this series :)
Awesome, it’s here!
So good. Thx for c++ networking tutorials. Before videos I think write self-protocol very hard, but I continuous coding my DataBase Product. JSON library parse easy body package ASIO sockets.
One of the tricks I used to have lots of objects was the server would use a linked list of objects. Then it would use the memory location on the server as the player id on the clients. That might be less clever when dealing with untrusted clients. But you could always have an array of valid player ids to check against. When a message comes in from a client, you validate the memory location is valid and then you don't have to actually search in memory for the object, you can go directly to it.
I use a similar trick when interfacing with Lua scripts, simply using the address of an object as it's uid in the script, also handy for finding the original object again. But yeah requires a bit of trust.
Well first of all let me congratulate you on your videos tutorials, they are great! I have been away from programming for a very long time having programmed mostly microcontrollers in c in the past, but i have taken this pandemic as an opportunity to finally dedicate my time to self learn c++, so i got bjarne's books and im progressing along... this series is of special interest for me not really for games but i am digesting your ideas and dapting them to (try) code an audio modem with networking acess to use over radio. Maybe its more than i can grasp with my current knowledge but having a goal helps. These concepts are hard to digest and its easy to get lost on the details and miss the big picture i guess that's something normal to "sort of begginners" like me. Still they provide a great source of help and again thank you javid. If you had to reccomend any kind of book or learning resource for c++ with a view not so much to teach you the language but more on general good practice strategies to solve programming problems what would those be? Is there any must read stuff? I am not much into games but its funny more and more i find that the problems posed by games are an exellent resource to adapt to other stuff, and a great learning resource in general. This comment is getting way too long! All the best and keep them coming! P.S. If you get the time to push on your audio series it would be appretiated!
Thanks Tasheido, Youve hit the nail on the head, games often present problems that are present in every other field, they just happen to be an entertaining way to learn about them. As for books, Im sorry but im a bit useless - Ive not read a programming book in a long time, so anything I have read would be woefully out of date (and out of print). My advice is to just get your hands dirty and start coding, but also realise that complex topics like networking do require you to have an understanding of the basics of computer systems, data structures, algorithms. Learning the syntax of a language is one thing, learning how to speak it is totally different, and that comes with hands-on practice and plenty of failure. Other than the famous Essential C++ book list on StakOverflow, I have nothing to recommend.
@@javidx9Well i still have my (reading and coding) hands full for the moment, still i think i can manage on self learning and keep motivated with what i have right now.
Its also funny how youtube came about to be at the same time a huge repository of crap and probably one of the best and more complete learning tools out there.. there are complete university level courses available on almost every other subject...that duality is food for thought. Cheers!
Can't wait for part 5
great tutorial!!! wow! clear and understable. respect. :)
The best tutorial Ive ever seen
I think this channel is THE best game development channel. All those others fail in comparison - Even Unreal Engine tutorials I think are poor in comparison.
You are great man. Thanks a lot👏👏
I'm really interested in that topic, and I would appreciate it if you could create more videos about it. Thank you so much
Pleaseeeee part 5 where is it!
nice I like it. reminiscing of old dream :)
You’re CZcams channel is pure gold!
thank you for the tutorial, easy s tier in this topic
Thanks a lot Javidx. I played with your example and found after server restart, clients do not auto reconnect and resume communication, will part 5 add this feature? 😊
Awesome ! Thanks a lot ~
superb!
great video
10:10 Isn't this model prone to client hacks and modulated packets?
Yes. The 'safer' approach is to send input to the server. However, to offset the the latency, you do client side prediction
Hi @javidx9. Thanks for your great tutorial. I've been working on a hero-based, top-down shooter game for a while. Would you give me some hint about how may I predict/reconcile, hero's abilities (Jumping, dashing, etc) smoothly for high latencies? Do you know any source about it?
thank you
Your very talented sir. I saw ur other video coding with java , and now here u are coding with another language again..
Your use of C is too nice and round all around. Wish I knew about unordered_map when tasked to do some projects.
i always used to use my own very slow and bad implementation of a map before I realized that unordered_map existed.
holy smokes you lovely human being i love you
Please please make the 5th part.
Thank you so much!
When are you going to make a video on top down city based crime game. Btw love your video
it "may" see a resurgence in a slightly different form on twitch later this year.
even better make it multiplayer lol Xd
Hi David Jones, thanks for the videos. Would you be making an engine using the Vulkan API?
I like your video and you .mr javidx
nice ;D
some things shall always be left up to the server since cheating exists
Yep!
I love you love you... love you
Awesome video series! I have a question. When I tried making a multiplayer game years ago, I wasted most of my time accidentally reading/writing the wrong data, data in the wrong order, or the wrong types to/from packets (this was udp). Do you know of a good way to solve this problem?
Eventually, I had the idea to define a class for each type of message that could be sent, and give it properties for each piece of data in that message. Then, I figured out a way to automatically read/write all of a Message object's properties to/from a packet without having to list them again. The problem was that it was kinda ugly and probably had some overhead. I'm hoping there's a common pattern to solve this problem...
Certainly, from a safety perspective, there is little more effective that having defined structs for all your messages, that way nothing comes a surprise when you are allocating memory at the other end...
@@javidx9 Ok, sounds like I was on the right track then, thanks. I'd love to see your implementation of that if you address that problem
Waiting for part 5.
Hi, can you suggest any books on this topics, and also from the previous 3 videos? Thanks, these 4 videos are awesome, any new ones?
Great channel, Part 5 and beyond?
I can't find part 5
Javid, did you ever implement OPC-based communication in your work?
This is awesome. It sparks a question though, how can server validate that the client code is official distribution and not some cheater's version? If I'm not mistaken, in this setup clients are able to update description of every player.
That could only be prevented on client't side with some anti cheat mechanisms. But you can not prevent cheat you can just make it hard to cheat.Thats what mp most games do.
I must advice you to use Ctrl+Shift+S instead of holding Snippet tool at taskbar other than that excellent series!!
Will you create a playlist to this series?
Hey. I'm following this series and first of all thanks for the videos, they are great and your way of explaining things is pretty interesting.
The thing is, could anyone point me directions on how could I implement the client with GameMaker? Right now I can connect the server with a GameMaker client and I'm trying to send messages with the same strcture of the ones that we use on the server, but I don't know exactly how could I do it.
Thanks :D
Sorry for a nooby question but can a client send some malicious position and velocity such that they can kinda ”speedhack”?
At the moment, absolutely they can, so not a noob question at all, a very astute one instead!
Server could do some consistency check and so reveal invalid client data and ban the client.
Hi Javid, I've been dabbling with packets with sfml and can create multiple instances of my game and connect to a server through sfml api, would you suggest I leave that for the moment and look at something like this series instead. I want to be able to support hundreds of connections. Do you have a few starting points for me? I've watched most of the first vid in this series... Do you think SFML if coded well could handle this for me, and I just grab some concepts from here etc, or do you have a resource you can recommend. Thank you
Javid can you or someone here tell me if the channel have a list of good resources to learn cpp and do amazing things like you do on your videos? if not where can I find such thing?
Hey sir, what do you think about nim-lang?
Hi, any reason not to use std::map as opposed to std::unordered_map?
Given that you are using integers as keys and they are already ordered and quite fast to compare,
I'd expect map to yield no worse code than unordered_map would.
EDIT:
std::hash seems to be the identity.
Furthermore, Godbolt.org seems to show that using map over unordered_map yields *more* machine code (on gcc-10 with with O3, O2 and Ofast I think).
So, that at least seems to argue in against (ordered) map, the end size was roughly 1.5× the size of my little test.
Although I didn't do a lot of tests, or profiled it, binary size can be misleading for speed :v
std::map requires a tree structure internally, and thus performance depends on how deep you have to search.
I don't recall the details of unordered_map, but from what he said it's a hash table, which means that as long as the hash function doesn't assign two items to the same space, the lookup will be constant _regardless_ of where the data is stored for anything that is stored in said map. More particular, it'll approximate the hash function invocation, + an array element lookup.
@@absalomdraconis That makes sense, because the bucket for ints is trivial, since the hash function can be just the identity.
Thanks
Do you think you will ever go over the basics of C++? Been trying to learn it after being stuck in C# for a while.
I'm unsure, there's many many many beginning C++ videos, I don't think I can add anything different. Maybe!
Just wondering. For the horde or alliance?
pls create playlist on this, thank you :D
Great video, I tried making a game after part 3 and was wondering why it was so slow. Not till this video did I realize that I was only processing one message per frame on the client side. (:
This video does the opposite! The clients are literally flooding the server with unnecessary messages. We will look at that in next episode.
@@javidx9 When are you gonna continue this series? Please upload more youre literally the best :(
@@javidx9 Awesome series. Please continue! :)
Hi javidx new to the channel, there is problem with the collision detection, when colliding with the corner between two solid tiles, the character slides to the side
on it's own, i think the issue is the because the first tile checked tries to slide the character around it's corner but since there's a solid wall next to it, it only moves you in the other axis, it's quite the bug, any tips on how to solve it
Sure, it's easily solved by sorting all potential collision candidates before resolution. I discuss this in my Rectangles video, but it's not included in this demo for clarity.
I am looking for Linux Tutorial to build Socket with Command Line Interface chat room connected by room username and password so its to connect two client.
Kinda like a private chat but the server can consist of a lot of room
how much more complex things get after this?
it is pretty simple so far.
how can i add the ability to send msgs (char*) from the server to a certain client
my god, i think im in love with you.
10:30 While your approach is nice in principle, it's harder to make it safe ; but I would argue optimistic updates on an action-based system is pretty complicated and you want to keep things simple. But having implemented some simple demos with action-based systems and no optimistic updates, I can tell you it's usually good enough, even for fast-paced games like racing or FPS ; and the server-authoritative design makes the whole thing easier to secure.
34:30 Mmh maybe it went a bit quick during the implementation and I didn't see, but since you're treating the player as just another entity, its position gets refreshed by server each frame, which negates any potential lag benefit one would have by using positions instead of actions?
What if the player lags out while walking into air and not a wall? What about diagonal movement? It'll look like they're moving somewhere they potentially aren't moving to on all the other clients because they don't know if they stopped moving or not. Or maybe I'm missing something
Clearly you are if you didn't watch previous video about diagonal movement, as suggested. If a player lags out, it's not too bad as the velocity vector will keep them going, and the collision detection will keep them in bounds, it may yield a corrective jump though later.
@@javidx9 By diagonal movement I meant that a Player will (seem to) be moving to the left/right if they lag out while walking diagonally into a horizontal wall, but I guess that doesn't really matter unless you have a connection with someone on the moon
how long have you been studying c++ ?
One downside that's pretty bad with this method is if the client knows all the player positions, it means they can also cheat. This means another player can't be hidden behind something, stealth, etc.
You can implement an anti-cheat that checks how much you've told the server to be moving and if it's more than you can travel in that time or just irregular, you force-teleport the player back
@@furitty Better yet, you just use a better design. This is very poor
@@WyMustIGo I don't think it is. This is what minecraft and a lot of other bigger games use.
@@furitty Well, you are wrong.
@@furitty it's far easier to prevent cheating if the server runs its own simulations from player movement commands, and only gives clients the specific information that should be visible to the specific players. Otherwise you get into the mess of trying to validate the client, validate the validator, ... which ends with rootkits in players' machines to ensure they're running the game "correctly". (Which should still be bypassible in hardware, although it would be more difficult.) If the server is king, players trying to cheat their personal simulations can only cheat themselves - it doesn't matter where you think your character is, if your opponents can snipe you at your real position on the server. Keep in mind, servers can be a lot more powerful than any computer an individual player is likely to own, because it's a large company running the things.
I was looking for something like this for years. I love you man, have my babies.
What about player to player collision, right now they are just walking through each other
banananana neo, bananananana sporin..
javidx9 is the world's smartest man.
Yes yes... upload the next video already where you make it minecraft 2.0
Networking and C++
I challenge you to tell me a harder combination
Awesome stuff, loving your tutorials ^_^
Thanks Vachila! Hmmm, harder than Networking and C++? In my experience, anything involving javascript... XD
Any language that features "comefrom" as an alternative to other branching systems...
@@javidx9 Really? 0_0
I do love JavaScript though, it's like a native language to me, been porting your tutorials to JavaScript all this while xD (they've been loads helpful, thank you for making them!)
Tried porting the 3D engine series, but as always, JS had reference issues and I got lazy, didn't finish it
@@absalomdraconis Huh, I'm confused?
Can you make box2d tutrorial on oclengine pls
now that the server does none of the work, how do you prevent hackers from going through walls :P
lol, well the server will be given some jobs to do, one of which may play a role in anti-cheating, as it stands though the other clients could do the checks.
Ano also any player can pretend as he is someone else so can manipulate other characters data.
@@sirynka Resolving that though is a one liner. Currently the player only has write access to the system via PlayerUpdate message. If the server receives this message it knows the id of the client that sent it. If that id does not match the id in the message, simply reject it, ban the client. Literal one liner.
@javidx9 better randomizer those ids then, haha
Why?
0:43 I know that these videos are free and I really appreciate that. They're great! But please understand that I don't criticise stuff because I hate you or am thankless.
I criticise because I consider respectful, constructive feedback as a gift. I also appreciate people critising me, because it gives me a chance to improve and understand what people disliked. Of course that doesn't mean that you have to incorporate that criticism, that's up to you. But it's better if people criticise than if they just press the dislike button or stop watching your videos without ever telling you why, isn't it?
I criticise because I think your videos are great and feel that you care about your content and want to know what you could improve.
I consider "people should not criticise me, because I provide my content for free" to be an unhealthy mindset.
And I've always felt that many STEM people feel the same way. We enjoy rational discussions without taking dissenting opinions as a personal insult. That's why I enjoy working in this field.
Of course there are also people who just write hateful and abusive "criticism". They're douchebags, no argument there.
Hope I didn't sound like a dick. I sincerely didn't mean it like that. Just felt like something I had to say.
This should all be the same for C right? After trying to learn C++ I've decided I should really just get my head around C first
Not really unfortunately. I use a lot of c++ specific ideas and tools here. Also, there are fewer and fewer reasons to learn C before C++ anymore, if it helps code in C, in C++!
Why do I feel like Javid studied electrical engineering in his bachelors, or am I right?
π = e = 3
@@___xyz___ jesus christ
@@CykPykMyk sin(x) = x ∀(0 ≤ x ≤ 1)
@@___xyz___ sin(x)/x = 1 when x -> 0
My dream is to make a Channel jusy like yours in my language. There's no such thing here
9:46 "this doesn't work" in regards to the server doing most of the position crunching is a small error, though I'm sure you're already aware. It's needed for cheating prevention and that rabbit hole
Doesn't this trust the clients a bit too much? Seems easy to make a pseudo client that can teleport :P
Most gamers like to sit at home alone. LMAO
Could you make detailed review of uNetworking/uWebSockets lib please?
Yet an other video that wasn't shown on my notifications or start page even when im subbed and have the bell set to "all" wtf is going on CZcams
Oo
tell me how to make a font size bigger in cmd window im working on my own game engine i thought you tech the best so here im
well you are the legend of programming history not javid the great javid