Example #1
0
def findAndRun(name, path):
    action = getCommand(name, path)
    if action == None:
        print "Command not found"
    else:
        print "Running action " + action["name"]
        commandLine = action["command"].split(" ")
        commands.runCommand(commandLine)
Example #2
0
def ishell(serverprops):
	while True:
		command = raw_input(">")
		command = command.split(" ")
		try:
			commands.runCommand(serverprops,command)
		except Exception as e:
			traceback.print_exc()
			print "error in command", command.split[0] 
def setFunction(env, i):
    function = ""
    commands.runCommand(env, '$')
    for c in i:
        if ord(c) is not ord('}'):
            function += c
        else:
            break
    for c in function[::-1]:
        env.push(ord(c))
    env.push(len(function))
    commands.runCommand(env, '>')
Example #4
0
def doCommand(passedInput=None, pipedInput=None):
    commandName = passedInput.split(' ')[0]
    if commandName is None or passedInput is None:
        print("we somehow processed a None parameter?")
        return
    parameters = shlex.split(passedInput)[1:]
    if commandName in localCommands:
        #print("we attempted to run a non-existing command. how.")
        #parameters = passedInput.split(' ')[1:]
        localCommands[commandName](parameters, pipedInput)
    elif commandName in cmd.getCommands():
        # if the command isn't internal then it's probably an external command
        # so, let commands.py handle that
        cmd.runCommand(commandName, parameters, pipedInput)
def runFunction(env, i):
    index = env.stackIndex
    commands.runCommand(env, '^')
    length = env.pop()
    function = ""
    for _ in xrange(0, length):
        function += chr(env.pop())
    for c in function[::-1]:
        env.push(ord(c))
    env.push(len(function))
    env.push(index)
    commands.runCommand(env, '^')
    for c in function:
        try:
            if commands.runCommand(env, c):
                i.next()
        except:
            parseShuggar(env, c, i)
Example #6
0
def processIncomingData(s):
	if s == incomingConnection:
		conn, addr = incomingConnection.accept()
		print("Connected to "+str(addr))
		connections.append(conn)
		connectionsBuffers.append([])
	else:
		try:
			data = s.recv(50)
		except:
			dropConnection(s)
			return
		if not data:
			dropConnection(s)
			return

		connectionIndex = connections.index(s)

		# Command structure: Length, Command, Args...
		# Response structure: Length, values
		# Below code allows for multiple or partial commands to be received
		if not onCopro and sys.version_info < (3, 0):
			data = list(map(ord, data))
		inputBuffer = connectionsBuffers[connectionIndex]
		inputBuffer += data

		# While there is a whole command in the buffer
		while len(inputBuffer) > 0 and inputBuffer[0] <= len(inputBuffer):
			command = inputBuffer[1 : inputBuffer[0]]

			# Act on the command. Terminate connection on command length of 0
			if inputBuffer[0] == 0:
				print('Terminating a connection')
				connections.pop(connectionIndex)
				connectionsBuffers.pop(connectionIndex) 
				
				s.close()
				return
			else:
				response = commands.runCommand(command)
				response = [len(response) + 1] + response
				try:
					s.send(bytearray(response))
				except:
					dropConnection(s)
					return

				# Remove the command from the buffer
				inputBuffer = inputBuffer[inputBuffer[0]:]

				connectionsBuffers[connectionIndex] = inputBuffer
Example #7
0
def connectClient(s):
    global newConnectionActive
    global connectedClients

    s.listen(5)
    print "Listening for clients.."
    c, addr = s.accept()

    newConnectionActive = True

    user = c.recv(1024)
    message = 'New connection from "' + user + '"'
    print(str(addr)),  #adding a trailing comma prevents a newline.
    relayAll('server', message)

    connectedClients.append((c, user))

    while True:
        try:
            message = c.recv(1024)
            if message == '/logout':
                break
            elif message[0] == '/':
                runCommand(message, c, user, listConnected('byaddress'),
                           listConnected('byusername'))
            else:
                relayAll(user, message)
        except:
            break

    connectedClients.remove((c, user))
    c.close()
    message = user + ' logged out.'
    print(str(addr)),
    relayAll('server', message)

    return
Example #8
0
def chatCommand(packetid, packet, serverprops):
	if packet['dir'] == 'c2s':
		if packet['message'].startswith('#'):
			command = packet['message'][1:].split(" ")
			commands.runCommand(serverprops,command)
			return {}
		elif packet['message'].startswith('/give '):
			msg = packet['message'].split(" ")
			item = msg[2]
			try:
				itemnum = int(item)
			except ValueError:
				if item in items.id2underName:
					itemnum = items.id2underName[item]
				elif item in items.item2underName:
					itemnum = items.item2underName[item]
				else:
					print "Unknown item: " + item
					return {}
			msg[2] = str(itemnum)
			if len(msg) == 4:
				num = msg[3]
				try:
					num = int(num)
				except:
					print "invalid number"
					return {}
				if num > 64:
					msg[3] = "64"
					packets = int((num - 64)/64)
					packet2 = {'message':"/give %s %s 64" % (msg[1],msg[2])}
					encpacket = mcpackets.encode("c2s",mcpackets.name_to_id['chat'],packet2)
					for i in range(packets):
						serverprops.comms.serverqueue.put(encpacket)
			packet['message'] = " ".join(msg)
			return packet
Example #9
0
def connectClient(s):
    global newConnectionActive
    global connectedClients

    s.listen(5)
    print "Listening for clients.."
    c, addr = s.accept()

    newConnectionActive = True

    user = c.recv(1024)
    message = 'New connection from "' + user + '"'
    print(str(addr)),                               #adding a trailing comma prevents a newline.
    relayAll('server', message)

    connectedClients.append((c,user))

    while True:
        try:
            message = c.recv(1024)
            if message == '/logout':
                break
            elif message[0] == '/':
                runCommand(message, c, user, listConnected('byaddress'), listConnected('byusername'))
            else:
                relayAll(user, message)
        except:
            break

    connectedClients.remove((c,user))
    c.close()
    message = user + ' logged out.'
    print (str(addr)),
    relayAll('server', message)

    return
Example #10
0
									chan = c
									l = chan.split('@')
									if len(l) == 2 and len(l[0]) > 0 and len(l[1]) > 0:
										if l[1].lower() == "grapevine":
											if useGrapevine:
												#print("grapevine used!")
												gsocket.msg_gen_message_channel_send(players[id]['name'], l[0].lower(), params)
												sendToChannel(players[id]['name'], chan, params, channels)
											else:
												mud.send_message(id, "Grapevine is disabled!")
										else:
											#print("Unrecognised channel location '" + l[1] + "'")
											mud.send_message(id, "Unrecognised channel location '" + l[1] + "'")
									else:
										#print("Invalid channel '" + chan + "'")
										mud.send_message(id, "Invalid channel '" + chan + "'")
								else:
									sendToChannel(players[id]['name'], c.lower(), params, channels)
							else:
								mud.send_message(id, "What message would you like to send?")
						else:
							#if players[id]['defaultChannel'] != None:
								#sendToChannel(players[id]['name'], players[id]['defaultChannel'], params, channels)
							#else:
							mud.send_message(id, "Which channel would you like to message?")
							
					else:
						runCommand(command.lower(), params, mud, playersDB, players, rooms, npcsDB, npcs, itemsDB, itemsInWorld, envDB, env, scriptedEventsDB, eventSchedule, id, fights, corpses)
			

def printString(env, i):
    length = env.pop()
    string = ""
    for _ in xrange(0, length):
        commands.runCommand(env, 'c')
Example #12
0
         if AegisServerAlpha.antiAttack(message,config.nick):
             ircsock.sendmsg(channel,AegisServerAlpha.antiAttack(message,config.nick))
         if user == ":PowderBot" and misc.detectBomb(message):
             ircsock.sendmsg(channel,misc.detectBomb(message))
         
         if FightBot.fight(message,user,config,channel):
             ircsock.sendmsg(channel, FightBot.fight(message,user,config,channel))
         if FightBot.check_accept(message,user,config,channel):
             ircsock.sendmsg(channel, FightBot.check_accept(message,user,config,channel))
         
         #Runs all the commands
         for command in commands.commands:
             if message.split(" ")[0] == config.commandChar+command or (config.unsafeCommandChar and (config.commandChar+command) in message):
                 #Multithreading :D :D
                 if config.userPerms.get(hostmask,0) >= commands.commands[command].permLevel:
                     if command not in commands.noThread:
                         t1 = threading.Thread(target=commands.runCommand, args=(channel, message,config,commands,command, hostmask, user , config.Output, ircsock))
                         t1.setDaemon(True); 
                         t1.start(); #t1.join()
                     else: commands.runCommand(channel, message,config,commands,command, hostmask, user , config.Output, ircsock)
                 
                                 
     elif ircmsg2["type"] == "PING":
         ircsock.ping()
     
     #Sends the output from the commands
     config.Output.run(ircsock)
 
 except KeyboardInterrupt: pass
 except:
     traceback.print_exc()