Skip to content

Instantly share code, notes, and snippets.

@TkTech
Created December 21, 2010 01:04
Show Gist options
  • Save TkTech/749318 to your computer and use it in GitHub Desktop.
Save TkTech/749318 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
#
# client_test.py
# pymc
#
# Created by Tyler Kennedy on 2010-12-20.
# Copyright 2010 Tyler Kennedy. All rights reserved.
#
import getopt, sys
import pymc.client.client
from pymc.core.exceptions import ProtocolError
def event_connecting(sender, address, port):
print 'Connecting to {0}:{1}...'.format(
address, port
)
def event_connected(sender, address, port):
print 'Connected to {0}:{1}.'.format(
address, port
)
def event_new_mob(sender, eid, etype, pos, yaw, pitch):
print 'New mob, id={0}, type={1}, pos={2}, yaw={3}, pitch={4}.'.format(
eid, etype, pos, yaw, pitch
)
def main(argv=None):
if not argv:
argv = sys.argv
try:
opts, args = getopt.getopt(argv[1:], 'hp:', ['help','port='])
except getopt.GetoptError as err:
print str(err)
return 2
port = 25565
for k,v in opts:
if k in ['-h']:
pass
elif k in ['-p', '--port']:
port = v
if len(args) < 3 or len(args) > 3:
print 'Usage: {0} [hp] <address> <username> <password>'.format(
argv[0]
)
return 2
# Setup the client, and connect to the server
client = pymc.client.client.Client(args[0], args[1], args[2], port=port)
client.on_connecting += event_connecting
client.on_connected += event_connected
client.on_new_mob += event_new_mob
client.connect()
# Run the main I/O loop
try:
client.loop()
except ProtocolError as err:
print err.msg
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment