Character moving in multiplayer

hi, i got a question,
i know how to create a character with a control characterControl, i got a simple game that runs everything pretty good,
but i got a big problem on wich is the “good way” to do it via spider monkey.
i got some choices but dont know wich one is correct here there are

1.-make the client read the inputs(left, right, up, down)
-send a message to the server with string(left,right…,and actual position)
-on the server (read the input from message and calculate the vectors walkdirection movedirection)
-broadcast this info to all the clients

2-make the client read the inputs(left, right, up, down)
-on the client calculate the vectors walkdirection movedirection
-send new position to the server
-broadcast new position from server to all players

i dont rly think any of those methods is pretty good, i dont realy understand this… cos if i only work with positions, a client will only be able to see himself animations, not other clients animations, and in the first method, could make a player to press buttons and see actions happening half of second later.

by the way, in case of need the game is a first person shooter.thanks for all.
other question.
i got a class called char that includes all player features, i think the way i have to deal in a multiplayer online is creating a new object of this class in server and in all clients, if this is right, wich is the better way to save info about this player, might be sql database? , or might be just a binary file with the object and load it each time this player connects?

i know i made tons of questions, im a java programmer, this is my first contact to video games and im pretty thanksfull to jmonkey for this software. if i finally end my online game and i get some incomes i will donate a big % to this helpfull project.
thanks for make it free and give us this chance to create a game that simple, im working with jmonkey tons of hours per day and im pretty happy about the quickly my game is increasing in complexyty. thanks

Well, animations are no different from position or any other stuff, you can synchronize them too

The answer is both choices.

The same movement calculations should be done on client and server.

You need the client to move the remote players given the last good information from the server (sometimes called dead reckoning) AND the client must move the local player in a similar way given input from the keyboard/mouse/gamepad/etc.

Local player inputs should be sent from the client to server where the same calculation is done server side. The server should then broadcast the new position, velocity and acceleration to the other clients. The velocity and acceleration ar e important so the client can interpolate postilions between server updates.

well, i dont work with aceleration and velociti, i only work with the given parameters location, walkDirection and viewDirection,

i hve to start to use aceleration and velocity?

other question about your answer.
if i understand u, when i press a key, for uxample “w” to move, i have to make the move methods on my client,
sent my localPosition, send my “w” pressed to the server, so the server send my w to all clients, and everyone apply the methods to solve my w pressed,
when i release “w”, i send it too so server and the other clients can stop the “w” method, then the server send to me and to all clients his final location and the server anwuer is like the “good one”, if some client included the client who pressed “w” have a different location, his location is corrected to the location the server have.

im so happy about ur fast answer.
thanks a lot

The problem with sending only location and direction is that the client can’t interpolate between server updates. You need to also send, at least, speed (velocity) so that the client can continue moving the remote players while it waits for another update from the server. Otherwise you’ll end up with jerky remote player movement.

The client should be sending inputs (“wasd” keys and mouse movements) to the server. The client doesn’t wait for the server to respond back but immediately moves the local player’s character. The server takes the inputs and does the same calculation the client does and sends the calculated vector updates to the other clients. Clients should only be doing movement calculations for their own local players.

Now the fun part is when the client and server disagree on where the local player is. The server should also be sending back it’s local player calculation to the client as well. If they disagree by some margin the client should use the server’s calculation going forward. This could cause perceived “warping” or “rubber banding”. The trick it to some how interpolate the difference between the server and client’s position.

That’s only true if you want prediction. And in some cases, prediction can be a quite lousy way to go. The Valve articles that I always post (daily lately) discuss ways to avoid doing this sort of prediction… they just delay rendering by 100 ms or so. But you are still going to be sending more than just a single update. (Like, batches of updates 20x per second or whatever.)