September 09, 2010, 03:40:47 PM
News: As promised, here is another update of the editor with improvements and bug fixes
Pages: [1]
Print
Author Topic: Racer: Server Plugin  (Read 704 times)
StormGnu
Full Member
***
Posts: 118


Script Programmer

wizzyz@hotmail.com
View Profile
« on: September 20, 2009, 10:58:57 AM »

Hello guys!

As some of you already know, I'm a pretty crazy person when it comes to programming!

Yesterday (read last night / today ) I made a client-server plugin for the Geist3D engine using a combination of Lua, Python and glue. It uses the built in Lua scripting language to interface with the Python client-server plugin using file IO with locks similar to those used in multithreaded programming.

I am fully aware of that Jochen has already implemented networking support in Geist3D. The Lua interface to the networking node is however lacking and I think we all know how busy Jochen is implementing a lot of cooler stuff then a simple high-score server. That said, this plugin is solely for keeping track of high-scores right now and possibly chat in future versions.

This plugin is  entirely optional and you won't even notice it inside Geist3D until you run the python client script located inside your editor folder. All releases of the Pangea: Racer Prototypes released by me will contain support for this plugin.

Anyways, were is the server at, you might ask. Right now it's included in the .rar below running on localhost by default because I can't keep my computer on at all times.

If we get down to it. This plugin is written in python 2.6, get it here.
This is how it works.
  • First download the latest release of the Pangea: Racer Prototype from this thread.
  • Then download one of the plugins below which matches the prototype version and place the files it in the main Geist3D Editor directory.
  • Launch the editor, open the Racer Prototype and press play.
  • Execute the 'High-Score Server.py' by simply double-clicking it.
  • Execute the 'High-Score Plugin.py' by simply double-clicking it.

Commands
/ping   -   returns pong
/nick [nickname]   -   Set your current nickname, used to store your score on the server
/send highscore   -   Sends your current score to the server
/get highscore [nickname]   -   Get the highscore of that nickname
/disconnect   -   Disconnect the plugin

This is an alpha of the plugin and it will probably undergo a total rewrite, at least the server-side.

Download
High-Score Plugin - 0.0.003
« Last Edit: September 20, 2009, 11:15:48 AM by StormGnu » Logged
spmisra
Newbie
*
Posts: 24


View Profile
« Reply #1 on: September 20, 2009, 12:06:58 PM »

That is really great. The thing is we are using 2 scripting languages again. What about if we use java only as scripting for long term? I mean java(Groovy) can also be interpreted. Just a thought.
Logged

~Thanks
Shakti
StormGnu
Full Member
***
Posts: 118


Script Programmer

wizzyz@hotmail.com
View Profile
« Reply #2 on: September 20, 2009, 12:17:44 PM »

Java is great in some ways but it can't really be compared to Lua which is pretty much made to be integrated into a C/C++ environment.

I love Lua and Python. Python will always be my first pick but the more I read about Lua the more I understand why Jochen picked it for Geist3D because it's so easy to integrate and extend.
Logged
Jochen Stier
Administrator
Sr. Member
*****
Posts: 498


Founder/Programmer

jochen.stier@gmail.com
View Profile
« Reply #3 on: September 20, 2009, 10:09:59 PM »

Quote
I am fully aware of that Jochen has already implemented networking support in Geist3D. The Lua interface to the networking node is however lacking and I think we all know how busy Jochen is implementing a lot of cooler stuff then a simple high-score server. That said, this plugin is solely for keeping track of high-scores right now and possibly chat in future versions.

The networking support I have experimented with so far is an environment server that maintains the physical state of the system. It is based on UDP and tailored towards real time performance. What we will still need in the future is a data server that maintains all of the remaining game state. For an MMO that can potentially become very large. So, keep it up.


I haven’t tried running it yet, because my entire mind is the clouds right now, but I am sure it runs. I will definitely add support for Lua sockets ASAP, then the client won’t have the install and run Python. I know the install is pretty large and with socket communication we can get around shipping Python as well.

Quote
What about if we use java only as scripting for long term? I mean java(Groovy) can also be interpreted. Just a thought.

I like Lua because it is so fast! At first I actually used the spidermonkey javascript engine, but that was inefficient and buggy. Then I integrated the python interpreter but that was also to slow. Lots of other game engines use Lua as well. I don’t know anything about groovy.

Logged
spmisra
Newbie
*
Posts: 24


View Profile
« Reply #4 on: September 20, 2009, 11:26:31 PM »

Yes I know of LUA. Its really fast and small and made to integrate with C/C++. And also it has a good set of libraries. A lot of game engines use it.
I was just suggesting an alternative. http://groovy.codehaus.org/
the main feature I liked about groovy is that it builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk. And also nearly all java code is Groovy code. So if some one writes in java, he essentially writes in Groovy. It runs on JVM, so no need for separate VM also. the only thing that can help us is for web programming and stuff we need not use any other alternative as it can act as Scripting and JAVA.  Also it has some features of python also.

Below is a set of features
# is an agile and dynamic language for the Java Virtual Machine
# builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
# makes modern programming features available to Java developers with almost-zero learning curve
# supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain
# makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
# increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications
# simplifies testing by supporting unit testing and mocking out-of-the-box
# seamlessly integrates with all existing Java objects and libraries
« Last Edit: September 20, 2009, 11:28:56 PM by spmisra » Logged

~Thanks
Shakti
StormGnu
Full Member
***
Posts: 118


Script Programmer

wizzyz@hotmail.com
View Profile
« Reply #5 on: September 21, 2009, 02:54:18 AM »

Jochen:
I would be really interested in working with some kind of data server communicating via Lua sockets. I still think that if we would decide on that, we should look at Python Stackless for the server side. At least for Pangea Online.

spmisra:
I looked at the site and read around a little. From what i can see, Groovy would be the perfect choice for any Java program which need scripting support. I might want to use it myself if i ever programmed some Java again. For Geist3D my vote goes for sticking with Lua for now, no need to change something that works well and is much faster then Python, Ruby and possibly Groovy ever can be.

Anyways I'm rewriting the server side for this plugin to be multi-threaded so that several user can connect to it at once. Once this is finished I will add chat support and then lay it to rest for a while as i resume work on the actual prototype.
Logged
Jochen Stier
Administrator
Sr. Member
*****
Posts: 498


Founder/Programmer

jochen.stier@gmail.com
View Profile
« Reply #6 on: September 21, 2009, 09:16:20 PM »

I looked at LuaSockets today but I didn't integrate it yet. From what I read you have to ship some .lua files with it, which is a security issue in my mind. I think I will just add some functions to the Geist3D network object; the one that every model has in the treeview by default. This way we can move a lot of the authentication, security into C++ code. Maybe we can also define a higher level protocol. It will just give us more flexibility. But at first I will provide some simple socket open/connect/bind functions which you can use for communication.

As far as Stackless python goes I think that’s a great idea. If it works for Eves then it will be fine for us as well. Plus, AFAIK Python has been designed for server side web applications. There is also Perl…


So, I will go ahead and provide my own Lua socket functions in the network object. Since you only need to make outward connections, I think you only need open/connect/send and receive. Maybe could also make it so that incoming data calls an event handler in the network object.
Logged
Jochen Stier
Administrator
Sr. Member
*****
Posts: 498


Founder/Programmer

jochen.stier@gmail.com
View Profile
« Reply #7 on: September 22, 2009, 04:55:54 PM »

I have just updated yApp.msi with a version containng  four additional functions in the network node necessary to open a stream based TCP socket. I have tested it a little bit but also attached the source code so that you can see what’s going on. The idea is that the sockets never block. Hopefully that is so. Don’t use this version for anything else but to play around with the communication. A more stable editor is still to come.


Here is the lua script I used to test the code in the OnDeposit handler of the network node. The IP address is that of google com. I could connect and send, but I did not receive anything; probably because google didn’t send anything.

Code:

socket = event:connect("74.125.127.105", 80)

event:send(socket,"hello")

print(event:recv(socket,120))  // 120 is the number of bytes to read.



Here is the C++ code for the Lua functions. Let me know if you need any changes !

 
Code:

int ComNetwork::connect(lua_State *L)
{
    SOCKET lSocket = INVALID_SOCKET;
    if (lua_isstring(L, 1) && lua_isnumber(L,2))
    {
        const char* lAddress = lua_tostring(L,1);
        int lPort = lua_tonumber(L,2);

        sockaddr_in lServerAddress;
        memset ((char *)&lServerAddress, 0, sizeof(struct sockaddr_in));
        lServerAddress.sin_family=AF_INET;
        lServerAddress.sin_port=htons(lPort);
        lServerAddress.sin_addr.s_addr=inet_addr(lAddress);

        lSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (lSocket != INVALID_SOCKET)
        {
            ioctlsocket(lSocket, FIONBIO, (ULONG*)1);
            if (::connect(lSocket,(SOCKADDR*)&lServerAddress,sizeof(sockaddr_in)) == SOCKET_ERROR)
            {
                ::closesocket(lSocket);
            }
        }
        else
        {
            LOG<0> () << "connect(): " << Message(WSAGetLastError());
        }
    }

    lua_pushnumber(L, lSocket);
    return 1;
}

int ComNetwork::recv(lua_State *L)
{
    sBuffer[0] = '\0';
    if (lua_isnumber(L,1) && lua_isnumber(L,2))
    {
        int lSocket = lua_tonumber(L,1);
        int lRequest = lua_tonumber(L,2);

        unsigned long lPending;
        ioctlsocket(lSocket, FIONREAD, &lPending);
        if (lPending >= lRequest)
        {
            int lReceived = ::recv(lSocket, sBuffer, lRequest, 0);
            if (lReceived != SOCKET_ERROR)
            {
                sBuffer[lReceived+1] = '\0';
            }
            else
            {
                sBuffer[0] = '\0';
                LOG<0> () << "recv(): " << Message(WSAGetLastError());
            }
        }
    }
    lua_pushstring(L, sBuffer);
    return 1;
}

int ComNetwork::send(lua_State *L)
{
    bool lResult = false;
    if (lua_isnumber(L,1) && lua_isstring(L,2))
{
        int lSocket = lua_tonumber(L,1);
        const char* lString = lua_tostring(L,2);

        if (::send(lSocket, lString, strlen(lString), 0) != SOCKET_ERROR)
        {
            lResult = true;
        }
        else
        {
            LOG<0> () << "send(): " << Message(WSAGetLastError());
        }
    }
    lua_pushboolean(L, lResult);
    return 0;
}

int ComNetwork::closesocket(lua_State *L)
{
    if (lua_isnumber(L,1))
    {
        int lSocket = lua_isnumber(L,1);
        ::closesocket(lSocket);
    }
    return 0;
}

Logged
StormGnu
Full Member
***
Posts: 118


Script Programmer

wizzyz@hotmail.com
View Profile
« Reply #8 on: September 23, 2009, 12:49:15 AM »

Awesome!

I'll spend some time testing this out later today.
Logged
StormGnu
Full Member
***
Posts: 118


Script Programmer

wizzyz@hotmail.com
View Profile
« Reply #9 on: September 23, 2009, 02:23:28 PM »

I'm not going to be able to test it out today because of school etc. but I'll give it a try as soon as I can.

Btw, when you say yApp.msi, where can I find that? I looked around on the FTP but everything there looked pretty old.

update
Never mind, found it. We who contribute once in a while should really get some kind of ftp accounts or something Smiley
« Last Edit: September 23, 2009, 02:25:28 PM by StormGnu » Logged
Pages: [1]
Print
Jump to: