-
Notifications
You must be signed in to change notification settings - Fork 1
/
mc-irc.py
executable file
·125 lines (100 loc) · 3.55 KB
/
mc-irc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python
# coding=UTF-8
import socket
#import multiplexlib
import time
import sys
import string
import select
import irc_class
import mp_class
import mc_dispatcher
# TODO: External configuration files
# IRC configuration settings
irc_server = 'irc.freenode.net'
irc_nick = 'VoxelHead'
irc_port = 6667
#irc_channel = '###linkulator'
#irc_channel = '##crawl-offtopic'
irc_channel = '##loafyland'
# Multiplexer configuration settings
mc_socket = '/home/minecraft/tmp/plexer.sock'
mc_port = 9001
mc_password = 'aardvark'
sock_list = []
dispatcher = mc_dispatcher.dispatcher()
# So, let's connect to IRC!
print( 'Attempting to connect to IRC' )
irc_conn = irc_class.IRC( dispatcher, irc_server, irc_port, irc_nick, irc_channel )
if( irc_conn.status['connected'] ):
sock_list.append( irc_conn.socket )
# And now, let's connect to the Minecraft Multiplexer
# TODO: Exception handling for Plexer not being there to connect to
print( 'Attempting to connect to Minecraft Multiplexer' )
mc_conn = mp_class.multiplexer_connection( dispatcher, '/home/minecraft/tmp/plexer.sock', None, mc_password )
mc_conn.connect()
if( mc_conn.status['connected'] ):
sock_list.append( mc_conn.socket )
mc_conn.cmd( 'say §7[§2!§7] VoxelHead Online.')
dispatcher.mc_conn = mc_conn
dispatcher.irc_conn = irc_conn
# sock_list = [ mc_conn.socket, irc_conn.socket ]
try:
while irc_conn.status['connected'] and mc_conn.status['connected']:
( sock_out, sock_in, sock_exception ) = select.select( sock_list, [], [] )
# See if there is anything pending from Minecraft or IRC
for s in sock_out:
if s == mc_conn.socket:
mc_conn.cycle()
if s == irc_conn.socket:
irc_conn.cycle()
# Make sure the IRC connection hasn't died on us
if( irc_conn.status['connected'] == False ):
irc_conn.connect()
# See if there is anything pending _for_ IRC
if irc_conn.status['joined'] == False:
irc_conn.join()
if( len( mc_conn.outbox ) > 0 ):
for message in mc_conn.outbox:
irc_conn.say( message )
mc_conn.outbox = []
# See if there is anything pending _for_ Minecraft
if(len( irc_conn.outbox ) > 0):
for message in irc_conn.outbox:
print( 'MCM < ' + message )
mparts = message.split()
#print( repr ( mparts[2] ) )
if len( mparts ) > 2:
if mparts[2][0] == "\x01":
if mparts[2] == '\x01ACTION':
message = mparts[0] + " §a* " + mparts[1].replace('<','').replace('>','') + " " + " ".join( mparts[ 3: ] )
mc_conn.say( message, surline = '§8[^]§a' )
irc_conn.outbox = []
# More vestigal code from the generic client.
# (sout, sin, sexc) = select.select([sys.stdin, ml.client_socket],
# [],
# [])
# if sout != []:
# for i in sout:
# if i == sys.stdin:
# line = sys.stdin.readline()
# if line == '':
# ml.disconnect()
# exit()
# else:
# pass
# ml.send_command(line.rstrip().decode('utf-8'))
# else:
# line = ml.receive()
# if line == '':
# ml.disconnect()
# exit()
# else:
# print line
# Exit on a ^C or other exception
except KeyboardInterrupt:
print 'Exiting.'
mc_conn.cmd( 'say §7[§c!§7] VoxelHead Offline.' )
irc_conn.disconnect( 'Process caught SIGINT' )
#except Exception, e:
# print 'Got exception: ' + e.__str__()