View Full Version : Game server.
ShowerThoughts
03-28-2009, 06:28 PM
Hello, my friends!
Like some of you know, a group of people and I are going to make a game.
My idea was to send all the information in 1 string.
Like :
"175;143;0;1;1;1;0;0;1;0;1;0" Or without ';'
Atleast, is this a good idea?
Second thing. How do we send this over a server?
How can we use our own pc as "server" and how to use for example Ruler's hosting service?
What are the requirements?
Laser
03-30-2009, 12:20 AM
What type of scripting are you planning on using?
For the data, that would be fine but you might want to also make up some encryption method so people can't mess with the data when it's being sent back.
This isnt a thing you make in a day, this is a very big thing, as Laser said -
you might want to also make up some encryption method so people can't mess with the data when it's being sent back. I would suggest you try to hack it yourself and see how easly it can get hacked, this is a very big factor in a game server.
ShowerThoughts
04-02-2009, 09:00 PM
I know it's going to be easy to be hacked but I have some tricks.
Harry
04-02-2009, 09:05 PM
You can make it use a PHP page to connect to.
IE:
if(isset($_GET['levelup]) && strlen(trim($_GET['levelup'])) > 0) {
$count = file_get_contents("THEIR-USERNAME.txt");
$count = explode("=", $count);
$count[1] = $count[1]+1;
$file = fopen("THEIR-USERNAME.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);
}
then just have it connect to their PHP file.
Example: <somehow to connect in what language you are using> <their username>.php?levelup=true
As for it not being hacked, I dunno :p Maybe make some secret code in it.
I know it's going to be easy to be hacked but I have some tricks.
Magic tricks, aces in your sleeve works in RL, this is the net, get used to it.
Grippy
04-02-2009, 11:25 PM
Hello, my friends!
My idea was to send all the information in 1 string.
Like :
Or without ';'
Atleast, is this a good idea?
The choice is going to depend a bit on how much data you are sending and how much freedom you want to support older versions of the client.
You didn't mention what language you are targeting, so for the sake of discussion I'll assume Delphi. Most of this applies regardless of language, though the details of how you parse messages will vary.
If you don't need a very large amount of data you can do a simple scheme using TStringList's support for Name=Value pairs. This makes for a very robust and easy to understand protocol where fields are named. On the other hand, you end up sending more data because you are sending the field names along with the data.
It works like this. When you want to send some data across the connection you create an instance of a TStringList, then you populate it with a list of strings containing your data using name=value pairs. You then read the .CommaText property to convert the list to a simple string (with quoted comma separated values), then send that string across the connection. At the other end you create a TStringList, receive the transmitted string and assign it to the .CommaText property. The TStringList will convert it back into a list of strings. To read the commands back you use the .Name property to get the values.
So what do you send? Again, depends on what kind of a communication model you are using. A simple Command-Response model is easy to deal with and versatile. It consists of a command, lets say a 'Login' command, and may include some parameters, we'll use UserName, Password and ClientVersion (the version number of the client software).
In a pas unit that is shared between the client and server applications you define the routines used to manage the communications protocol. Something like this:
unit CommProtocol;
interface
uses Classes, Sysutils;
const
CommandID = 'CMD';
cmdLOGIN = 'Login';
type
TLoginRequestInfo = record
UserName : string;
Password : string;
ClientVersion : string;
ErrCode : Integer;
end;
function IsLoginRequestMsg(Parser: TStrings): Boolean;
procedure SetupLoginRequestMsg(InStrings: TStrings; UserName, Password, ClientVersion: string);
function ParseUploadLoginRequestMsg(Parser: TStrings; var LoginRequest: TLoginRequestInfo): Boolean;
implementation
function IsLoginRequestMsg(Parser: TStrings): Boolean;
begin
Result := (Parser.Values[CommandID] = cmdLOGIN);
end;
procedure SetupLoginRequestMsg(InStrings: TStrings; UserName, Password, ClientVersion: string);
begin
InStrings.Clear;
InStrings.Add(CommandID+'='+cmdLOGIN)
InStrings.Add('UserName='+UserName);
InStrings.Add('Password='+Password);
InStrings.Add('ClientVersion='+ClientVersion);
end;
function ParseLoginRequestMsg(Parser: TStrings; var LoginRequest: TLoginRequestInfo): Boolean;
begin
Result := IsLoginRequestMsg(Parser);
if Result then
with LoginRequest do begin
UserName := Trim(Parser.Values['UserName']);
Password := Trim(Parser.Values['Password']);
ClientVersion := Trim(Parser.Values['ClientVersion']);
end;
end;
end;
So now on the client when you need to log into the server you just have to do something like this:
procedure TGameClientClass.DoLogin( User, Pass : string );
begin
sl : TStringList.Create;
try
SetupLoginRequestMessage(sl, User, Pass, GameClientNumber );
SendStringToServer( sl.commaText );
finally
sl.Free;
end;
end;
This builds a stringlist that looks like this:
CMD=Login
UserName=whatever
Password=what,ever
ClientVersion=whatever
After it goes through the CommaText routine it is a simple string (notice that the user's password had a comma in it):
CMD=Login,UserName=whatever,"Password=what,ever",ClientVersion=whatever
See how it quoted the Password field so that the comma could pass through? It'll handle the quote characters automatically too.
The 'SendStringToServer()' method is just a placeholder in this example. It would do something like use the current TCP connection to the server to send the string.
On the server side you would have a TCP receive method that parsed the messages coming from the client:
procedure TGameServerClass.TCPReceive(AContext: TIDContext);
var
Buffer : TStringList;
LoginRequest : TLoginRequestInfo;
begin
Buffer := TStringList.Create;
try
// Get the incoming text
Buffer.CommaText := AContext.Connection.IOHandler.ReadLn;
// Process the command
if ParseLoginRequestMsg( Buffer, LoginRequest ) then begin
DoLogin( LoginRequest );
BuildLoginResponseMsg( Buffer, LoginRequest.ErrCode );
SendMessage( AContext, Buffer );
end
else if ParseSomethingElse1( Buffer, SomeThingElse1 ) then begin
DoSomethingElse1( SomethingElse1 );
BuildSomethingElse1ResponseMsg( Buffer );
SendMessage( AContext, Buffer );
end
else if ParseSomethingElse2( Buffer, SomeThingElse2 ) then begin
DoSomethingElse2( SomethingElse2 );
BuildSomethingElse2ResponseMsg( Buffer );
SendMessage( AContext, Buffer );
end;
finally
Buffer.Free;
end;
end;
If you don't want your data on the wire in the clear where people could snoop on it, just use a TCP component that encrypts it before sending it.
Now, obviously, if you are sending rapid sync updates like character position and suchlike where you might generate a lot of data you can just encode the data into a string and use the same system.
You just build a string containing your update and send it. The command might be:
const
cmdPlayerSync = 'PlySnc';
And you can give it a single parameter that consists of your sync data encoded into a string:
procedure SetupPlayerSyncMsg(InStrings: TStrings; SyncData: string);
begin
InStrings.Clear;
InStrings.Add(CommandID+'='+cmdPlayerSync)
InStrings.Add('SyncData='+SyncData);
end;
Your player object might have a property that generates the sync data based on some of it's information, like the world position, current animation, health, etc:
function TPlayer.GetSyncData: string;
begin
result := Format( '%s,%s,%s', [WorldX, WorldY, Health] );
end;
So then the message that goes up to the server would look like:
CMD=PlySnc,"SyncData=2343,8989,12"
On the server you would read the SyncData field and then parse it by field number nstead of by field name. You could do this by dumping the Value['SyncData'] into a second string list's .CommaText which would split the string at the commas resulting in a list containing:
2343
8989
12
Then you'd just read that string list by using defined constants:
const
cSyncWorldX = 0;
cSyncWorldY = 1;
cSyncHealth = 2;
var
syncData : TStringList;
begin
... := syncData[cSyncWorldX];
... := syncData[cSyncWorldY];
... := syncData[cSyncHealth];
end;
Second thing. How do we send this over a server?
How can we use our own pc as "server" and how to use for example Ruler's hosting service?
You'll have to find a hosting service that supports whatever platform you intend to run the server on. IME most web hosts don't let you run things like game servers, but there are plenty of hosting solutions available.
Hope that helps.
MylesMadness
04-03-2009, 12:38 AM
Holy crap. Thats one wall o' text
Grippy
04-03-2009, 03:58 PM
Holy crap. Thats one wall o' text
If you'd been paying my consulting rates the content of that post would have cost you $300.
ShowerThoughts
04-03-2009, 04:17 PM
If you'd been paying my consulting rates the content of that post would have cost you $300.
Hehe :p
Thank you for your reaction.
I was almost close to my idea. I just didn't write it out.
We want to make it in C++ but I prefer C#.
www.home.impsoft.info
Go to projects.
We have allot of plans. But we didn't put everything on the site.
Client :
Contains a timer every 50 mili secs(A good amount of time) will connect to server and POSTS his Ingame data like X, Y and the shit.
After done that it receives other players data's and shows them in the client
Server:
Shares all the info with the other clients.
I got allot of school shit and home shit going on.
I don't have allot time right now, so we are going to continue when we have a vacation. or allot spare time.
I am still reading OpenGL stuff and trying to do it in C++.
Will edit it later have to go.
Hugolord
04-03-2009, 04:31 PM
lol.. here we go with the c++ again -,-
ShowerThoughts
04-03-2009, 04:35 PM
lol.. here we go with the c++ again -,-
What about you shutting up AGAIN?
Be helpful or mind your own business?
I made a thread about a engine before.
this was about the SERVER.
I am sick of you stop complaining!
Thanks for others who reacted!
~Hermpie/Fatheadz
Grippy
04-03-2009, 07:12 PM
Hehe :p
We want to make it in C++ but I prefer C#.
Managed or unmanaged C++?
I'd recommend going with C#, or at least with managed C++, it's a much more friendly environment, you'll spend a lot more time writing code and less wondering why things aren't working.
I mentioned it before, but under C# you wouldn't worry about the communication much, you'd just set up a connection using WCF and let it manage the details of how the data is transported.
Client :
Contains a timer every 50 mili secs(A good amount of time) will connect to server and POSTS his Ingame data like X, Y and the shit.
Be careful about doing things with timers. You'd be better off sending an update when it is needed (such as when the character has moved) or when a maximum time-between-updates limit (say, 5 seconds) has been reached, but never at a rate greater than some limit. This keeps your network utilization more dynamic, allowing your server to handle more clients.
Your update rate should also take into consideration network performance and server load. If the server is heavily loaded it should be able to tell clients to back off on their update rates. This means that clients may experience some consistency errors (images of other players may jump to new positions suddenly when their actual position does not match their predicted position), but prevents the server from dying under the load and dumping everyone offline, or just becoming unusably slow for everyone.
Also consider making updates smarter than just 'my current position is'. Instead send updates that let the other clients accurately predict your position. For example, in RS your character moves at a rate that is determined by a small number of variables. If you know where a character is and where his flag is, you know where he'll be for the next few seconds, so there is no need for him to constantly send position updates. If the player controlling that player clicks somewhere and moves the flag an update would be sent.
ShowerThoughts
04-03-2009, 07:36 PM
It is going to be controlled with the arrows on the keyboard.
We will send a X and Y of the middle of the player.
We have a Player Image that we will use headed to right and left from the X and Y and the standard image height's and widths we are going to draw the char. so we only need to send one position ;)
Do you want to talk on Msn, and how old are you? (Hermen Otter [At] Live . nl
~Fatheadz/Hermpie
Grippy
04-03-2009, 09:35 PM
Can you tell us some more about the gameplay? I think you said it was going to be a 2D format. Is it top-down, open world format, or like a side-scroller? What is the player's objective? Are they trying to escape something, solve a puzzle, rescue the princess? What sort of challenges does the player encounter while they are trying to achieve the objective? Are there physical obstacles, moving enemies, puzzles, etc? Does the player obtain things from the environment with which they overcome the challenges (e.g., weapons to defeat enemies, equipment to overcome obstacles, etc)?
Zyt3x
04-05-2009, 08:47 AM
Bump! This is a great thread for us ppl that make games, I started on a fake-3d game yesterday and I'm only done with the variables and some few "createUser" procedures, I do have a server, but I don't know how to use it, or IF I can use it at all...
Hermpie: Add "selmer- anderssen (at) hotmail .com" (without spaces)
ShowerThoughts
04-05-2009, 09:56 AM
Finely someone being nice :p
I am currently talking with Grippy(You're nice to :p) about the C# game.
Added.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.