Jump to content


Photo

Gamemaker Winsock 2 Udp Wrapper / Aes Cryptography


  • Please log in to reply
21 replies to this topic

#1 the_keeper

the_keeper

    GMC Member

  • New Member
  • 6 posts

Posted 23 July 2008 - 08:07 PM

This DLL can be used for playing multyplayer games on the Internet. The comunication is based on the UDP, because that gives more freedom in writing games, but you will have to figure out what will be structure of the comunication and what synchronization is needed.

The cryptography algorithm it uses is the AES. It encrypts 128 bit (16 bytes) blocks and uses 128, 192 or 256 bits (16, 24 or 32 bytes) long keys.



1. Init - Initializes Winsock
a) returns 0 if all is OK, other, if it is not.

2. Create - Open a Port with given number; if port == 0, then it will be chosen at random by the OS
a) returns -2.0 if the the variables are wrong;
-WSAGetLastError() when there is an error;
'socket handle' (always >0) when all is OK;

3. Sendto - Send defined number of bytes to chosen IP:port, with defined Timeout
a) returns -2.0 if the the variables are wrong;
-WSAGetLastError() when there is an error;
number of transferred bytes when all is OK;

4. Recvfrom
a) With this function you can receive bytes from a defined IP:port (with defined Timeout) or
b; if you write 'any.222.222.222:61111' (global.ReceiverIP_Port2 = 'any.222.222.222:61111'), from any IP. Then you must read from what IP:port the packet came from (etc. global.ReceiverIP_Port2).
c) returns -2.0 if the the variables are wrong;
-WSAGetLastError() when there is an error;
-3.0 on timeout;
number of transferred bytes when all is OK;

5. Close - Close the socket
a) returns 0 when all is OK;
-WSAGetLastError() when there is an error;

6. Cleanup - Unloads the winsock library
a) returns 0 when all is OK;
-WSAGetLastError() when there is an error;


7. Encrypt - Encrypt a 16 byte Message with defined Key; if the message is shorter, then the functions will add 'p' to fill the strting to 16 length.
a) returns 0 when all is OK;
-2.0 if the the variables are wrong;

8. Decrypt - Decrypt the Ecrypted Message with defined Key
a) returns 0 when all is OK;
-2.0 if the the variables are wrong;



The functions call the following system calls:
1. Init - >WSAStartup()
2. Create -> socket(), bind()
3. Sendto -> sendto()
4. Recvfrom -> recvfrom(), connect()
5. Close -> closesocket()
6. Cleanup -> WSACleanup()


All functions call strlen() to obtain the string length. Therefore, you should *ALWAYS* initialize the string parameters with the desired number of bytes (length) in order for the functions to work! We've done this, because of some GM limitations about the number of string parameters of a function and the way GM handles pointers and string parameters. Remember to *ALWAYS* check the return value of all functions.



//Simple Code for usage

//Define Functions
global.Init=external_define('networking.dll','Init',dll_stdcall,ty_real,0);
global.Create=external_define('networking.dll','Create',dll_stdcall,ty_real,1,ty_real);
global.Sendto=external_define('networking.dll','Sendto',dll_stdcall,ty_real,4,ty_real,ty_string,ty_re
al,ty_string);
global.Recvfrom=external_define('networking.dll','Recvfrom',dll_stdcall,ty_real,4,ty_real,ty_string,ty_st
ring,ty_real);
global.Cleanup=external_define('networking.dll','Cleanup',dll_stdcall,ty_real,0);
global.Close=external_define('networking.dll','Close',dll_stdcall,ty_real,1,ty_real);

global.Encrypt = external_define('networking.dll','Encrypt',dll_stdcall,ty_real,3,ty_string,ty_string,ty_
string);
global.Decrypt = external_define('networking.dll','Decrypt',dll_stdcall,ty_real,3,ty_string,ty_string,ty_
string);

//Code Action
//Simple Caption for Choosing Mode
k = get_string('
1 - Server
2 - Client','');

//A message that will be sended
global.Message = '1234567890123456';
//The Server's IP and OpenedPort
//if You define Port as '0', it will be random generated

global.ReceiverIP_Port = '127.0.0
.1:6111';
//The Client's IP and OpenedPort
//if You define Port as '0', it will be random generated

global.ReceiverIP_Port2 = '127.0.0.1:6112';
//Timeout can be
//0 - forever - until receive
//1-... - time in milisecond

global.Timeout = 0;

//Initialise EncryptedMessage - 16 bytes - becase of Encrypt Mechanysm
global.EncryptedMessage = ' ';
//Initialise DecryptedMessage - 16 bytes - becase of Encrypt Mechanysm
global.DecryptedMessage = ' ';
//Initialise Key - it can be 128, 192, 256 bits (16, 24, 32 bytes)
global.Key = '1234567890123456';


if (k = '1') {
//Create Caption - becase of the two windows on the screen (when I use same computer)
window_set_caption('Server');
//global.Init
result=external_call(global.Init);

//global.Socket - open port 6111 on server
global.Socket = external_call(global.Create, 6111);

//Receive from the Client
result=external_call(global.Recvfrom, global.Socket, global.EncryptedMessage, global.ReceiverIP_Port2, global.Timeout);
//Decrypt
result=external_call(global.Decrypt, global.EncryptedMessage, global.DecryptedMessage, global.Key);
//show on the screen
show_message(global.DecryptedMessage);


};


if (k = '2') {
//Create Caption - becase of the two windows on the screen (when I use same computer)
window_set_caption('Client');
//global.Init
result=external_call(global.Init);

//global.Socket - open port 6112 on client (the same computer) - must be different (when You use different computers, the port can be the same)
global.Socket = external_call(global.Create, 6112);

//Encrypt
result=external_call(global.Encrypt, global.Message, global.EncryptedMessage, global.Key);
//Send to Server
result=external_call(global.Sendto,global.Socket, global.EncryptedMessage, 16, global.ReceiverIP_Port);



};


//Close the opened port
result=external_call(global.Close, global.Socket);

//Close the Socket
result=external_call(global.Cleanup);

//Game end
game_end();


Link: http://game662.hit.bg/networking.dll
Created by: amd_bg & The_Keeperpln

Edited by the_keeper, 24 July 2008 - 08:46 AM.

  • 0

#2 LoveMalvina

LoveMalvina

    GMC Member

  • New Member
  • 15 posts

Posted 25 July 2008 - 05:46 PM

Nice.
  • 0
The power within me...

#3 the_keeper

the_keeper

    GMC Member

  • New Member
  • 6 posts

Posted 28 July 2008 - 05:43 PM

Is this any faster than GMSock or 39DLL?


You can make it as fast as you want, because this is UDP comunication dll, and it allows to not lose trafic for receiving answer, when the package is received (if the game is synchoronised with 'OppMissle1.x = ...' or 'global.OppLife1 = 2000' or this kind).

If You have any other questions, write me and I will answer You with pleasure.
  • 0

#4 amd_bg

amd_bg

    GMC Member

  • New Member
  • 4 posts

Posted 28 July 2008 - 07:59 PM

The DLL just checks the parameters of the functions and then passes them to the system calls that are listed in the first post. We cannot say how fast it is, but I think that passing parameters and calling the Winsock functions is pretty fast and should be the same as all other networking DLLs. However, we haven't tested them. BTW, the DLL uses blocking sockets. However, you can control the timeout of recvfrom() calls. What exactly do you mean by fast?
  • 0

#5 amd_bg

amd_bg

    GMC Member

  • New Member
  • 4 posts

Posted 31 July 2008 - 08:15 AM

Hi again,

What do you mean by faster? This is an UDP wrapper and the two things that influence speed is the network speed and the speed of calling the functions. Maybe you mean the second. As I said, it should not be any slower, but we haven't tested any other DLLs.
  • 0

#6 cephei

cephei

    GMC Member

  • GMC Member
  • 801 posts

Posted 01 August 2008 - 09:51 PM

Nice work but it is kinda useless since 39dll covers all of this an ALOT more.

UDP: Faster (than TCP) since its a connection-less protocol, just sending out a message to a port and hoping that it will arrive
TCP: Slower (than UDP) because it verifies data and checks if packages have arrived (+ connecting with 3 way handshaking*)

*handshaking> (pc1) Hello i want a connection, (pc2) yea fine lets do it, (pc1) ok =)
  • 0

#7 amd_bg

amd_bg

    GMC Member

  • New Member
  • 4 posts

Posted 02 August 2008 - 09:57 AM

Nice work but it is kinda useless since 39dll covers all of this an ALOT more.

UDP: Faster (than TCP) since its a connection-less protocol, just sending out a message to a port and hoping that it will arrive
TCP: Slower (than UDP) because it verifies data and checks if packages have arrived (+ connecting with 3 way handshaking*)

*handshaking> (pc1) Hello i want a connection, (pc2) yea fine lets do it, (pc1) ok =)



We just needed UDP communication and AES 256 and decided to write it and share it with others. :lol:
  • 0

#8 Doogie_Forever

Doogie_Forever

    Dog Warrior

  • GMC Member
  • 824 posts
  • Version:GM:Studio

Posted 02 August 2008 - 01:45 PM

It still could be useful in my eyes, receiving data from specific people connected to your server could help decrease spammage but other than that I personally have no use for it.

EDIT: Wait a minute, are you saying this is Guaranteed UDP Sending, meaning no traffic will be lost? So its like TCP but no packet ordering, etc. So it still should be fast?

Edited by Doogie_Forever, 02 August 2008 - 01:48 PM.

  • 0

#9 cephei

cephei

    GMC Member

  • GMC Member
  • 801 posts

Posted 03 August 2008 - 10:41 PM

@Doogie Forever: No its not (i hope so, because TCP is faster than managing UDP+Checkout)
EDIT: Ok it may be faster, i don't really know, but cmon, why reinvent re wheel? (actually i dont know if that phrase is known in other countries than germany, but i hope so ^^)

We just needed UDP communication and AES 256 and decided to write it and share it with others. smile.gif

Ok, thats fine. (even then you could edit the 39dll source and cut out the part you dont want)

Edited by cephei, 03 August 2008 - 10:42 PM.

  • 0

#10 amd_bg

amd_bg

    GMC Member

  • New Member
  • 4 posts

Posted 07 August 2008 - 06:52 PM

All I was trying to say is that we wanted the specific functions and wrote them. We've never used other DLLs, we didn't try to reinvent the wheel. We just did it for fun and for ourselves. Then we decided to share it with others, so that it can possibly be useful to someone else. :D We don't argue that it is the best or something like that... ;)

As for guaranteed delivery, this is just a wrapper. It calls directly the WinAPI functions.
  • 0

#11 BrokenGlass

BrokenGlass

    GMC Member

  • New Member
  • 524 posts

Posted 10 August 2008 - 07:53 AM

Is this any faster than GMSock or 39DLL?


39DLL is winsock, just as this, you cant "make" it faster, its all the way you code your game. Winsock is winsock.
  • 0

#12 the_keeper

the_keeper

    GMC Member

  • New Member
  • 6 posts

Posted 11 August 2008 - 05:06 PM

39DLL is winsock, just as this, you cant "make" it faster, its all the way you code your game. Winsock is winsock.


That's why I wrote
"You can make it as fast as you want, because this is UDP comunication dll, and it allows to not lose trafic for receiving answer, when the package is received (if the game is synchoronised with 'OppMissle1.x = ...' or 'global.OppLife1 = 2000' or this kind)."

There is small changes that we must do in the code, for being much easy used in game codes.


The dll was written for our game (Yu-Gi-Oh The Power Within), at the moment we are working over the translation of the forum (http://tpw.getforum.org), who is about the game.

Edited by the_keeper, 12 August 2008 - 05:20 AM.

  • 0

#13 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 18 August 2008 - 05:21 AM

Wow nicer and easier then 39dll :D 10/10 WuUp WuuuUp :P
  • 0

Posted Image


#14 the_keeper

the_keeper

    GMC Member

  • New Member
  • 6 posts

Posted 18 August 2008 - 11:51 PM

Thank you :lol:
:D
  • 0

#15 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 19 August 2008 - 08:32 PM

:) maybe Tcp aswel eh? :GM031: 20/10 then lol
  • 0

Posted Image


#16 the_keeper

the_keeper

    GMC Member

  • New Member
  • 6 posts

Posted 19 August 2008 - 08:50 PM

It is possible, with somenew functions, this weekend - maybe... I don't promise :)
..
  • 0

#17 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 19 August 2008 - 10:07 PM

It is possible, with somenew functions, this weekend - maybe... I don't promise :)
..


Your Ub3r 1337, thankyou.
  • 0

Posted Image


#18 LoveMalvina

LoveMalvina

    GMC Member

  • New Member
  • 15 posts

Posted 23 August 2008 - 01:55 PM

It's easier, yes, but is it more functional than 93dll?
No matter what, I will write the online part of the game, usind 39dll, not this. When it beats the quality of 39dll, then I will replace it with this one. :)
  • 0
The power within me...

#19 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 23 August 2008 - 10:00 PM

Hmm.... I like 39DLL better.

However, 39DLL hasn't had updates for years.
  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.


#20 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 23 August 2008 - 10:04 PM

Yes 39dll has more features, but this is simplier therefore more productive for alot of people
  • 0

Posted Image


#21 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 17 July 2012 - 09:25 PM

please re-upload
  • 0
When I finish University, I would like to work for a BIG software Company like;SENJEN COMPANY. I'm obsessed with them! Period!

#22 Razon

Razon

    GMC Member

  • GMC Member
  • 268 posts
  • Version:GM:Studio

Posted 06 October 2012 - 02:57 AM

http://www.mediafire...sc1g9l0cgrtllls
  • 0