November 21, 2024, 07:29:15 pm

The Gang Garrison 2 Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

NOTICE: Wondering where all the forums have gone?

Join the community Discord server!

Pages: [1]

Author Topic: Lobby server source code available  (Read 10573 times)

MedO

  • Owns this place
  • *****
  • Karma: 151
  • Offline Offline
  • Posts: 1752
Lobby server source code available
« on: December 13, 2011, 02:24:26 pm »

This one is only really interesting for programmers. Are you a programmer? No? Then what are you still doing here? Get out!

They gone? Alright. Fellow programmers, you can find the Python source code of our new and improved mod lobby server on Github now, under the ISC license. It's quite messy in overall structure, but hey, I was re-learning Python as I wrote it. Feel free to make it more modular and send back a pull request if you feel so inclined. Or write a statistics module that draws awesome graphs on the status page. Or use the protocol description to add lobby support to your upcoming multiplayer game (you can use the lobby server on our VS - just ask first please. And use a different Lobby ID if it's not related to GG2.)

The repository is here. This is also where you should report any issues.
Logged
Quote from: Alfred North Whitehead
It is the business of the future to be dangerous; and it is among the merits of science that it equips the future for its duties.

Quote from: John Carmack
[...] if you have a large enough codebase, any class of error that is syntactically legal probably exists there.

Orpheon

  • 2011 Haxxy Award Winner
  • *
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Lobby server source code available
« Reply #1 on: December 13, 2011, 02:57:39 pm »

This made my day:
Code: [Select]
                mod = matcher.group(6)
                if(mod=="OHU"):
                    server.infos["game"] = "Orpheon's Hosting Utilities"
                    server.infos["game_short"] = "ohu"
                    server.infos["game_url"] = "http://www.ganggarrison.com/forums/index.php?topic=28839.0"
                else:
                    server.infos["game"] = mod
                    if(len(mod)<=10): del server.infos["game_short"]


Also, I want to follow in case something interesting happens.
Logged

nightcracker

  • NC
  • Full Member
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 516
  • PyGG2 dev
    • NC Labs
Re: Lobby server source code available
« Reply #2 on: December 14, 2011, 04:43:27 am »

Your expirationset class is quite ugly. Here is a better version:

https://gist.github.com/1476083

It's not nice to try and expire the keys whenever possible, by calling (the previously called cleanup_stale) expire_keys all the time (in add, remove, etc). It's more efficient and clear to the user that he/she has to call expirationset.expire_keys() himself, when he/she wants it.

I also removed the use of OrderedDict. If the one found in the repo is the same as the default implementation (collections.OrderedDict), your use also was flawed. It stores the order of ADDING to the dict, not keeping the dict sorted by values (as you assumed, which I found since you use break in your cleanup_stale loop).

So, my version isn't as focused on performance, because I don't think it will be necessary. If it will be necessary you should replace the inner dict with a binary tree.
« Last Edit: December 14, 2011, 04:52:48 am by nightcracker »
Logged

MedO

  • Owns this place
  • *****
  • Karma: 151
  • Offline Offline
  • Posts: 1752
Re: Lobby server source code available
« Reply #3 on: December 14, 2011, 05:11:48 am »

I wasn't quite happy with the expirationset myself, will look at your version.

The OrderedDict is required though, it is a backport of the standard OrderedDict to make it available on older versions of Python (like the one we are using on our server). Also, I am aware of which order the entries are stored in. Since the entries are timestamped on insertion, the insertion order is the same as the timestamp order (assuming monotonic time, but even a small clock hitch would just slightly delay the removal of some entries).

Edit: also, longer analysis at the gist.
« Last Edit: December 14, 2011, 06:10:35 am by MedO »
Logged
Quote from: Alfred North Whitehead
It is the business of the future to be dangerous; and it is among the merits of science that it equips the future for its duties.

Quote from: John Carmack
[...] if you have a large enough codebase, any class of error that is syntactically legal probably exists there.

nightcracker

  • NC
  • Full Member
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 516
  • PyGG2 dev
    • NC Labs
Re: Lobby server source code available
« Reply #4 on: December 15, 2011, 02:24:40 am »

lso, I am aware of which order the entries are stored in. Since the entries are timestamped on insertion

Oh damn, of course! Well, forget that I said that your usage is flawed, because it obviously isn't.

But I still think using an ordered set is not necessary. Only if you need to call expire_keys VERY often (which I doubt) the performance benefit is non-trivial. Another idea for circumventing the ordered set is storing two dictionaries (values and times) and an index. Every time something gets added it gets added to the expirationset you add the value to the values dict (with the index), and the time to the times dict (with the same index). Then you increment the index.
Logged

Sape

  • New Account
  • Karma: 0
  • Offline Offline
  • Posts: 2
Re: Lobby server source code available
« Reply #5 on: September 21, 2013, 07:27:46 pm »

First, sorry for my bad english, second i know the topic is a little old but i want to host my own lobby, i installed Python 2.7 (i try 3.2 also) and when i run for example (in CMD console) Python lobby.py i get this error:



any idea?.. i'm new to this stuff.
« Last Edit: September 21, 2013, 07:29:17 pm by Sape »
Logged

Orpheon

  • 2011 Haxxy Award Winner
  • *
  • Karma: 15
  • Offline Offline
  • Posts: 6409
  • Developer
Re: Lobby server source code available
« Reply #6 on: September 28, 2013, 02:39:19 pm »

First, sorry for my bad english, second i know the topic is a little old but i want to host my own lobby, i installed Python 2.7 (i try 3.2 also) and when i run for example (in CMD console) Python lobby.py i get this error:



any idea?.. i'm new to this stuff.
You need to install Twisted.
Logged

MedO

  • Owns this place
  • *****
  • Karma: 151
  • Offline Offline
  • Posts: 1752
Re: Lobby server source code available
« Reply #7 on: September 29, 2013, 07:04:01 am »

You can get it from here: http://twistedmatrix.com/trac/
Logged
Quote from: Alfred North Whitehead
It is the business of the future to be dangerous; and it is among the merits of science that it equips the future for its duties.

Quote from: John Carmack
[...] if you have a large enough codebase, any class of error that is syntactically legal probably exists there.

Sape

  • New Account
  • Karma: 0
  • Offline Offline
  • Posts: 2
Re: Lobby server source code available
« Reply #8 on: October 01, 2013, 06:02:25 pm »

Ok, thanks for your help!
Logged
Pages: [1]
 

Page created in 0.029 seconds with 36 queries.