A Simple Multiplayer Game

How can there not be a simple example. I’m talking about 2 boxes that are players that the server controls their movement.

MONKEYZONE is the worst example for multiplayer. Does ANYONE have an exmaple like MonkeyZone without all the AI, dumb car, stupid following, and everything else that is not needed for multiplayer. I’m trying to look through the source of MZ and it’s total hickory with tons of nonsense from AI and vehicles.

MonkeyZone sucks, Lets figure out a BETTER SIMPLE MULTIPLAYER EXAMPLE.

@HunterLong said: How can there not be a simple example. I'm talking about 2 boxes that are players that the server controls their movement.

Because it is not a simple thing. I have already told you how to do it… if that was not enough of an explanation then this is too hard for you. Come back to the problem when you are a better coder.

@zarch said: @HunterLong

You are asking for a simple example - but there is no such thing. Networking a game is not and never will be simple. We aren’t just telling you that to be awkward or keep you out of some super secret club. It’s hard. Even if we dressed things up in a simple example by making that example simple we would strip out all the stuff that makes it actually work in a real-world scenario.

zarch, i find that hard to believe. MonkeyZone is an example. but it’s an example with a bunch of bullshit in it. So, if MonkeyZone was created, a simpler multiplayer client/server CAN BE CREATED. I don’t know why you say this is impossible. Screw it being a game. JUST A SIMPLE MULTIPLAYER EXAMPLE. If i can see a box client walking around on my screen, i’ll be happy.

Once i figure out a basic example, i’m going to comment on the source, and make available for the other lost jmonkey users.

I say that YOU CAN LEARN THIS. Only thing you need to to is ACTUALLY TRY. Even with such limited capabilities like yours IT IS POSSIBLE. James Hetfield learned to sing so you can learn to code.

Do you really want to upset and attack or blame everybody around you because of your own incapability? Why can you not try and work on what you have: Two examples, one that apparently is totally transparent to you (I doubt even that) and one that is too complicated for you to understand. Try work your way up so you do understand the second example.

WHAT YOU WANT TO DO IS NOT SIMPLE, YOU WILL HAVE TO UP YOUR SOPHISTICATION LEVEL OR YOU WILL FAIL MISERABLY. Having others think for you won’t give you a game, try using some FPS mod instead, it will probably be better for you.

I’m not trying for a game. I’m wanting a good example. The following is not a game:

-flycam is attached the the player (a blue box)
-client #2 signs in, (a blue box appears for client #1)
-when i press W i want to see client #2’s screen see client #1 move.

I’m talking about boxes. NOT A GAME, NO AI, NOTHING CRAZY. A better example is what i need. I’m not asking anyone to create my game. I’m asking for a better example than “MoneyZone”. MonkeyZone is a cluster of stuff i don’t need.

So what do you do with that then? And why do you find it so hard to make that out of the chat example? if(message = newObjectType){addNewObject();} Whats so hard about that? Its only hard for you is because because you completely refused to read the tutorials, you rather wait in front of your browser and press F5 and wait that the code just appears on your screen. When looking at the documentation (I know you’ll say “but I looked at the docs!!”) you probably just looked for the sentence “Heres how to do what you, Mr. HunterLong, want to do, step by step, just for you” – wasn’t there, closed the wiki. :roll: Now you sit here and demand that other people solve your problem that actually did do what I say and did learn how the engine, networking and games in general work.

3 Likes

I dont usually participate in threads, as i find what other people offer much smarter answers but im sorry, i cant holdd myself this time.

There are multiple things you must first consider, about what is involved in what you have described:

  1. Monkey Zone is just a simplefied API that supposed to abstract the networking layer just a little bit and provide easier to use api geared specifically for gaming applications. If you dont find it easy to learn or w/e there are other ones (maybe even better ones) out there, such as KryoNet, which also come with examples of use and so on.

  2. By example what you mean(rather than say) is i am completely new to game networking, where can i find some working code so i can learn from it. Which is totally fine, but i am not sure you are catching this difference(based on peoples frustration when they try to explain this).

  3. Which brings us to the final point, because you are new at this, you may not realize quite the amount of stuff you need to accomplish before you see anything happen on the screen. This amount of “stuff” is in much greater ammount than in a non multiplayer game, both from technical and architectural standpoints, case in point, you might want to look into articles that discuss the following:

– TCP protocol RFC http://www.ietf.org/rfc/rfc793.txt
– TCP limitations
– UDP RFC http://www.ietf.org/rfc/rfc768.txt
– UDP limitations
– Protocol design
– Data compression using deterministic algorithms
– State synchronization
– Both data interpolation, and data extrapolation (not just linear, but spline->clamped/natural, cubic/bicubic-> for cameras, and so on)
– Network architecture and packet routing.
– Caching
– And much more to actually fit this into the model view controller of any engine because there are certain threading issues that come up
– Also threading, and the rest of graphics.

Jmonkey may save you from writing all of this stuff youself, but it doesnt mean that you dont have to know any of it to use it, especially for multiplayer games.

Granted you dont need all of it at once, but to see anything on the screen you definately do. Otherwise first stick to command line and JUnit tests.

6 Likes

You shouldn’t dismiss MZ… it shows you how to setup a lobby, exchange handshakes and other messages, and record connected clients. But mostly, it is just a source of info. Not the bible or anything. Nobody asks you to worship it.

From there, from your client update loop, every x (fraction of a second), send the position of the client to the server and have the server broadcast it to all other clients. All clients, when receiving the message, update the position of the other players, locally. And voilà, your boxes are moving.

Now, if you want an authoritative server, you aren’t asking for something simple anymore. But what I just described can be done by looking at MZ. Forget about the more complex parts (like I’m doing, for now).

NB: MZ has indeed a bug concerning the display of players connected, in the lobby. I posted a message in the MZ thread about how to solve it, at least on the nifty side.

norman, ive been reading the wiki/docs and loved the chat-server example perfect example. i just need an example of HOW TO MOVE USER IN MESSAGE (on client side, messages are already sent “Client #1 moved to 0,0,100” and server sends it back to the clients. But my main point in this entire thing, was to get an example of moving a player (with that player id (example: Client #1). I cannot find the actual movement of other clients sides anywhere because MZ has many other items. And i’m not just sittin here waiting for an answer, I WISH. I am learning new things in the mean time, and always going back to multiplayer functions. I just need one straight up example, for moving a client with .setLocationRotation / Translation under a message coming back from server.

okay, is pseudo-code enough?
[java]//CLIENT
//receive method – execute on openGL thread, messages come in on another thread: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:multithreading

void applyMessage(final Message message){
app.enqueue(new Callable() {
public Void call() throws Exception {
if(message == makeNewBoxMessage){
rootNode.attachChild(box);
boxList.add(newBox, makeNewBoxMessage.ID);
}
else if(message == positionMessage){
spatial.setPosition(message.getPosition);
}
else if(message == removeBoxMessage){
Spatial box = boxList.get(removeBoxMessage.ID);
rootNode.removeChild(box);
}

return null;

}
});
}

//SERVER
void addNewBox(){
sendNewBoxMessage(boxID);
}

void removeBox(){
sendRemoveBoxMessage(boxID);
}

void update(float tpf){
for(int boxID=0; boxID<boxes.size; boxID++){
Transform boxPos = getNewBoxLocation(boxID);
sendBoxPositionMessage(boxID, boxPos);
}
}[/java]

Cause if not its getting really impossible to help you.

Wonderful. is there a way to add

[java]void applyMessage(final Message message){
app.enqueue(new Callable() {
public Void call() throws Exception {
if(message == makeNewBoxMessage){
rootNode.attachChild(box);
boxList.add(newBox, makeNewBoxMessage.ID);
}
else if(message == positionMessage){
spatial.setPosition(message.getPosition);
}
else if(message == removeBoxMessage){
Spatial box = boxList.get(removeBoxMessage.ID);
rootNode.removeChild(box);
}

return null;

}
});
}[/java]

inside of:

[java] @Serializable
public class ClientListener implements MessageListener {
public void messageReceived(Client source, Message message) {

if (message instanceof HelloUser) {
  // do something with the message
  HelloUser helloMessage = (HelloUser) message;
  System.out.println("Client #"+source.getId()+" received: '"+helloMessage.Location()+"'");
  //helloText.setText("Client #"+source.getId()+" received: '"+helloMessage.Location()+"'");
        
} // else...[/java] 

mainly the “enqueue” inside of the ClientListener Where would I add the enqueue?

[java]public class ClientListener implements MessageListener {
public void messageReceived(Client source, Message message) {
applyMessage(message);
}
}
[/java]

http://www.javabeginner.com/

1 Like

pspeed, I have already done that, but I keep on getting error:

[java]Client #0 received: ‘(0.0, 65.95016, 0.0)’
Jan 29, 2013 12:54:00 PM com.jme3.network.base.DefaultClient handleError
SEVERE: Termining connection due to unhandled error
java.lang.NullPointerException
at mygame.Main.applyMessage(Main.java:511)
at mygame.Main$ClientListener.messageReceived(Main.java:120)
at mygame.Main$ClientListener.messageReceived(Main.java:110)
at com.jme3.network.base.MessageListenerRegistry.messageReceived(MessageListenerRegistry.java:74)
at com.jme3.network.base.DefaultClient.dispatch(DefaultClient.java:409)
at com.jme3.network.base.DefaultClient$Redispatch.messageReceived(DefaultClient.java:417)
at com.jme3.network.base.ConnectorAdapter.dispatch(ConnectorAdapter.java:133)
at com.jme3.network.base.ConnectorAdapter.run(ConnectorAdapter.java:175)
Jan 29, 2013 12:54:00 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Client is not started.
at com.jme3.network.base.DefaultClient.checkRunning(DefaultClient.java:119)
at com.jme3.network.base.DefaultClient.send(DefaultClient.java:223)
at com.jme3.network.base.DefaultClient.send(DefaultClient.java:208)
at mygame.Main.simpleUpdate(Main.java:485)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:241)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:662)[/java]

applymessage is as followed:

[java] void applyMessage(final Message message){
appclient.enqueue(new Callable() {
public Void call() throws Exception {
helloText.setText(“Something passed in apply!”);
// HelloUser helloMessage = (HelloUser) message;
//women.move(helloMessage.Location());
return null;
}
});
}[/java]

HelloText is null. Now its getting really silly, you don’t need help in a forum, just time to grasp java. NPE is the easiest Exception to trace.

[java]//helloText.setText(“Something passed in apply!”);[/java]

was set. it still crashes.

Then appclient is null. You seem to lack even the most basic debugging skills which is going to make everything you do a million times harder.

May I recommend many of the wonderful engines that require little to no coding? At least until you get a chance to learn Java.

There is Game Maker:

That has a visual code editor that is not really coding.

I hear you can also get pretty far in Unity without coding: http://unity3d.com/

LAWL guys, gimmi a break. Game Maker? That’s the dumbest crap in the world. And I haven’t even touched Unity. I have

[java] Application appclient;[/java]

which shouldn’t make it null? hm?

Variables are null until you set them.

We are not a Java help desk. Please learn Java before trying to write a Java game. I’m sure there are many fine Java forums or mailing lists that can help you with these basic general non-JME specific Java questions. I know there are also tons of tutorials online both as web pages (like at javabeginner.com) and videos.

I must be missing something here… I did set…

[java] Application appclient = new Main();
appclient.start();[/java]