I'm new to unity, I thought it was going to be a piece of cake, but now I'm thinking I bit off more than I can chew.
I'm trying to make an authoritative server game, where the client players send their desired movements to the server, then the server sends back to all clients, the actual movement position information.
When a client connects to the server, the server uses RPC calls to create the player objects on all of the clients. In the player script Awake() function, I create a NetworkView object, and attach it to the player object dynamically for synchronization. So all player clients are doing this as each new player connects to the game server, so everybody can see everybody else.
The problem I have is when the player client wants to move, the client tries to do RPC call to the server using the dynamically attached NetworkView, to send the desired movements, but the RPC call fails, giving an error on the SERVER (not the client), that the server cant find the NetworkViewID.
My code didn't print this error, so I guess it must be code deep inside unity that printed it when it received the RPC message from a client, and tried to match it up with a corresponding NetworkViewID on the server, when it could not, it printed the error?
I'm just wondering how unity works.... does object "A" on all clients and server have the same NetworkViewID, and object "B" on all clients and servers have the same ID (but different ID from "A")?
If so, how do NetworkView objects that are instantiated on clients and server know which ID to assign themselves so they all match up when this is being done on different computers over the network? Is this done automatically by unity, or do I have to send the ID myself to all NetworkView objects?? But I cant talk to the objects to tell them which ID to use, since I dont know the NetworkID in the first place, since that is apparently needed to talk to the NetworkView objects! Its like trying to ask someone their name, but you need their name in order to ask them. So that cant be how it works.
My problem is that at first, the player object has no NetworkView on it. After the object is created, the script on player object dynamically attaches a NetworkView. Since this is done on all clients, and on the server almost at the same time, how will they all know to assign the same ID to the same objects, so that they can RPC each other?
Also I read somewhere that the "owner ID" is always zero?
Sorry I'm new to unity, and trying to figure it all out. Can anyone give me the inside scoop on all this?
Related
I am building an extension pack for a single player computer game, the extension pack will be purchased with steam's API and then I will have a representation of all the steamids of all the players with the items that they have purchased in my database.
Here's my concern: when a player logs in and sends a request to the server to get all the extension packs that they own and receives a response back, there needs to be some sort of a representation of the answer in the code, whether it is a boolean that represents access to a specific extension pack or a disabled button for items that they don't own. Can't players just edit that button/boolean using dll injection to gain access to that extension pack or even monitor the response from my server and change it? What would be the right way to do such a thing?
I am trying to understand data synchronization in Unity network development.
First Problem that I am facing is to understand unity3D server client model.
1
My basic understand is that one machine behaves as server + client and other simply client.
But in following graphics when hosted from PC build there is no server at all????
When I host it from Unity Editor now there are both server + Client.. why???
2
The other problem I am trying to solve that is to make such a behavior in which if I press space button at server it increments the server score.
Same goes to client when space is pressed at client it increment the client score.
No progress at all because I am unable to figure it out how to separate the server date from client data. Trying to get the reference of two different Text objects if it is server it gets the server text from hierarchy and if it is client make it to get the client text object from hierarchy.
I hope Graphics are self self explanatory.
When you host from standalone builds you can't see who's the host directly in inspector on client. You can create UI to display information about network identity and make sure everything is correct.
for the first question, remember:
When you Join game as a Host You are Server + Client
When you Join game as a Server you are only server.
When you join game as a Client you are only client
You check these thing in build and develop your OWN GUI to view the checks as you mentioned.
Yes you can differentiate client and server using these checks
if(isLocalPlayer){
//yes this is the local player
//The class must be derive from networkBehaviour to access this property
}
and You can also use Network class to check is Server.
I am wanting to give back to a small gaming community. The idea is to make an app that acts like a chat client to connect to the game servers. I am trying to grasp the concepts on how connections work through examples I've found on the web, since I am self taught by seeing examples.
So far the examples I found are for connections on the same network. What I need is some kind of example that will allow me to connect from different networks or at least an explanation on what I need to do. Also I need to be able to get around a router without with setting port forwarding on the router.
In the end the app will be connecting to the game developer's server but I need a working app before I get his permission to connect to his servers.
Any help will be most appreciated. If any additional information is needed to help just ask and I'll do my best to fill in the gaps.
That is a very broad question, but I try to give you as much information as possible from by point of view. As I'm not yet sure if you want to have a P2P Connection (game-application to game-application) or a standard server model, I will just mentioned different approaches to this problem.
Adobe has support for P2P since a long time. Read some FAQ, esspecially "How does RTMFP differ from RTMP?" (I try to choose Sources with infographics, as that helped me to understand it).
What you really should start playing with and making first steps in, should be NetConnection. This is the very basic Function that will allow you to communicate to a Server running e.g. PHP or connecting to a Flash Media Server (FMS). FMS is inpartcular interresting for you, as it really boosts the ideas what you game could do, but setting up a FMS is not that easy,to host a own instance is even more complex. So if you come to the conclusion that you want to travel the road of using a FMS, I can suggest you Onyx Server. They mainly marketing theirself as a Streaming service, but in reality you will get access to a FMS for a ok'ish price (FMS instances on Amazon were way worst the last time I checked).
The FMS basicly only a Flash AS2 File with some extra Commands. Your FMS can handle real-time (!) persistent connections (!) with any client that connects to it. Everyone is able to connect to the server at first, and you can then choose in your FMS Script what a client have to bring to the table to stay on the server or is rejected. After that, you have a very string tool for a Game. For example, you could have a game instance connect to it, tell the server that an enemy was hit and the server near-instantly (the speed is really amazing, there is no feeled delay, it really is instant. Its called SharedObjects) pass this information down to the enemy game instance. I used FMS only for one project and it was a very long ride to understand it and work with it, but it was a really nice experience, as you code the Server in the "same" language like the game itself (AS2, AS3 = ECMA).
If you dont want to spend money at this stage, you can use the Adobe RTMFP Instance at p2p.rtmfp.net. It is, as far as I know, only for testing and you will be rejected if you misuse the service for a real project, but for starting and testing it will do. If you use the Cirrus Engine, you can even follow this Tutorial. You will find sample code in there:
// Cirrus connect info
private const SERVER:String = "rtmfp://p2p.rtmfp.net/";
private const DEVKEY:String = "{YOUR_DEVELOPER_KEY}";
// Used to connect to the Cirrus service
private var _netConnection:NetConnection;
_netConnection = new NetConnection();
// Listen for status info
_netConnection.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
// Connect to Cirrus using our unique URI
_netConnection.connect( SERVER + DEVKEY );
My adive for you would be: Try getting comfortable with NetConnection. It is really straight forward. When I first started using it, I had a couple of days struggeling and reading a lot on the web, but I learned a lot doing so. You should too. Use NetConnection and try to create two simple AS3/FLA instances of your code that both connect to the same domain (use the adobe rtmfp domain for now) and try to exchange some simple String-Data between these instances.
To take some of the pain of your shoulders, add the minimum amount of listeners to your NetConnection like so:
//Main NetConnector
nc = new NetConnection();
//Troubleshooting Listener
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
//nc.objectEncoding = ObjectEncoding.AMF0; //Default
nc.client = this;
nc.connect("https://some-domain");
////////////////////////////////////////////////////////////////////////////////
/// CALL ERROR LISTENER
////////////////////////////////////////////////////////////////////////////////
private function status_handler(e:NetStatusEvent):void {
//trace("NetStatusEvent");
dispatchEvent(new CallEvent(CallEvent.CALL_NATIVE_NET_STATUS, e, true ));
}
private function securityErrorHandler(e:SecurityErrorEvent):void {
//trace("SecurityErrorEvent");
dispatchEvent(new CallEvent(CallEvent.CALL_NATIVE_SECURITY_ERROR, e, true ));
}
You will get alot of errors and netStatus and NetSecuriy Events. Flash will often run into Sandbox-Violation errors when you now know what you are doing. That can be frustrating but if you keep it up, google every error and compare you implementations with the implementation of others, you will wrap your head around this and can do really neat stuff with it.
I recommend you google sources and tutorials for NetConnection and stick to one that is on your level of knowledge.
Good Luck.
Last semester we had to develop the game Ludo in JavaScript and HTML/CSS. That was pretty easy. Now we have to develop a backend with GWT (Java) to create a multiplayer game. Sadly, we haven’t got much information on how to develop with GWT and the exercise is quite difficult at the beginning.
At the moment I am trying to create a kind of lobby where different players can join.
My idea was to use some input fields, where the player could enter his name and join the lobby. But I don’t know how to give the other clients the information that a new player has joined.
I created an asynchronous interfaces (RPC) where a player could submit his name to the server (Like this example). This works ok. But how should I share this information? Our docent said we should use JSON to share information’s, but I don’t know how this should help in this situation.
Is there a way to send information’s to the clients? I read a lot and just find to use additional libraries as gwt-comet.
I have really now clue how I could go on. I’m thankful for every help and information!
Greetz
You have two options: push and pull.
"Pull" option:
Other players get required information when they join the lobby and/or do something else. You can also schedule to pull this information periodically (like once every 10 minutes). You can use the same RPC mechanism to get data from server to a client. "Pull" means that a client initiates the request and server responds with the information.
"Push" option:
When a new player joins, the server pushes this new data to all other players. The best solution depends on your game implementation. Comet is a good option, as Jean-Michel mentioned, but it's more complicated and "expensive" from resources point of view. You should use this option if you need real-time status updates for your game.
I would suggest Errai and ErraiBus in particular. From Java perspective you are only sending some events via event bus (observer GoF pattern) and all the magic with Ajax Push is happening behind the scenes.
For security purposes I want to source out some logic parts of the game out onto the server.
For example (Java Applet):
I have a player that shoots items to get points. For each successfull shoot, there will be called a function on the server that checks if it was legal and how many points the player gets and adds them to the total points. Total points are kept on server and a copy of actual total points is sent to the applet for displaying.
Now my questions:
I want to use a php script for the server side operations. Are there faster solutions?!
How can I handle this for each user that plays this game. For each request, there must be a new thread (which will already be handled by apache webserver) and I save the total points to a SESSION variable until the game is over.?!
Thanks!
regards matthais
Using a PHP script from within Apache might not be the best performing/scalable solution, but it may be a quick way set up and test your game.
Be aware that with HTTP you open a new connection every time you send a request to the server. This is a serious overhead! (EDIT: sorry, got mixed up here, since HTTP 1.1 persistent connection is the default. But there is still an overhead for each HTTP request!)
Maybe you want to create your own server listening on some TCP port (in any language of your preference). Of course, you'd have to implement the security layer on your own (or include a third party library).
This actually boils down to a question of urgency and available resources.
EDIT
For your question #2: Using PHP session variables sure is a good approach (but maybe not scalable). Otherwise, saving data as cookies may be a second possibility, but may be prone to manipulation again.