Sign in to follow this  
ddn3

Free Matching Making Service on PC?

Recommended Posts

I'm afraid you'll have to give us a little more information than that.

I think that there are many free web-based matchmaking solutions that you might be able to use; almost all of them would run on a PC because a PC can run Apache / MySQL / PHP.

Or are you talking about UDP matchmaking for NAT punch-through?

Share this post


Link to post
Share on other sites
Btw, here you go:

from twisted.internet import reactor, protocol
from twisted.protocols import basic
import os
import sys
import time
import urllib


class Session(object):
def __init__(self, type, ip, name):
self.ip = ip
self.type = type
self.name = name
self.lasttime = time.time()

# Matcher keeps a list of sessions, and can return a list of
# sessions that match a given key and is not too old
class Matcher(object):
def __init__(self):
self.sessions = {}
def update(self, ip, type, name):
self.sessions[ip] = Session(type, ip, name)
def search(self, pattern):
now = time.time()
# do incremental clean-up of the session list, one item per query
todel = None
ret = []
for k in self.sessions.iteritems():
if k[1].lasttime > now - 120:
if pattern in k[1].type:
ret.append(k[1])
else:
todel = k[0]
if todel:
del self.session[todel]
return ret

matcher = Matcher()

class Protocol(basic.LineReceiver):
def lineReceived(self, line):
global matcher
if len(line) > 512:
# don't allow ridiculous sizes
self.transport.loseConnection()
return
parts = line.split(" ")
ret = ["error: no command given"]
if len(parts) > 0:
ret = ["error: unknown command '%s'" %
(urllib.unquote(parts[0]).strip(),)]
if len(parts) == 2:
if parts[0] == 'MATCH':
q = matcher.search(urllib.unquote(parts[1]).strip())
ret = ["found %d matches" % (len(q),)]
for i in q:
ret.append("%s %s %s" % (urllib.quote(str(i.ip.host)),
urllib.quote(i.type), urllib.quote(i.name)))
elif len(parts) == 3:
if parts[0] == 'LIST':
matcher.update(self.transport.getPeer(),
urllib.unquote(parts[1]).strip(),
urllib.unquote(parts[2]).strip())
ret = ["ok"]
for l in ret:
self.transport.write(l + "\r\n")
self.transport.loseConnection()

class Factory(protocol.ServerFactory):
protocol = Protocol

def run():
reactor.listenTCP(54321, Factory())
reactor.run()


if __name__ == "__main__":
run()





I just googled "python twisted tutorial" and spent 30 minutes writing some code. You run it by installing Python 2.6 and Twisted (both are free downloads), then simply:

python matcher.py

It will listen on port 54321, and accepts two kinds of commands (one line each):

LIST some-type-here some-name-here
MATCH some-substring-here

LIST puts a listing into the database under the appropriate type and name. MATCH searches for any listing that is newer than 2 minutes and contains some-substring-here within the "type" part of the listing. All arguments should be URL encoded, so spaces should become %20. Similarly, return values are also URL encoded.

Matches are returned one per line, of the form:
ip-address type-string name-string

No given command can be longer than 512 bytes.

[Edited by - hplus0603 on February 13, 2010 2:35:05 AM]

Share this post


Link to post
Share on other sites
Thanks hplus0603! Sorry for the lack of info, I'm not sure myself about the requirements. We were looking for some low cost solution for our casual games, for connecting PC <-> PC and maybe iPhone <-> PC or iPhone <-> iPhone game.

I'll look into Twisted, thanks for the heads up and the code ! :D

Thanks again!

-ddn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this