''' i am going to implement both user dictionary, AND list of connections. thus, when in wk 2, i would just do something like data,addrs=clisock.recv(1024); with multiple connections, what i will do, is loop through each connection, and repeat the above listening for data and address. so it ought to be for q in clientele:

sacktoysSoftware and s/w Development

Dec 13, 2013 (3 years and 6 months ago)

74 views

'''

i am going to implement both user dictionary, AND list of connections.

thus, when in wk 2, i would just do something like

data,addrs=clisock.recv(1024); with multiple connections, what i will do, is

loop through each connection, and repeat the above listening for

data and address.

so it ought to be

for q in clientele:

data,addrs=q.recv(1024)

'''

'''set up TCP socket, bind it, set it as listening socket, initialise a client list,

set blocking to off.

INITIALISE SOCKETS'''

import socket

HOST='127.0.0.1'

SPORT=5001


srvrsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

srvrsock.bind(("", SPORT))

srvrsock.listen(5)

srvrsock.setblocking(0)

#INIT ARRAYS,ETC

clientele=[]

roomDict={'painting': 'a const
able painting hangs on the wall',


'carpet': 'the carpet is faded and jaded',


'cupboard':'why there has to be a cupboard in a room, i do not know, but, unoriginally, there is',


'vase':'tra la la. there would just happen
to be a vase sat on the cupboard. prob got a key inside. why not
have a look.'}

allObjects={}

inv={'rucksack':' you have got nada inside the bag. nada!'}

usrs={}


def broardcast(roomDescr):


for u in usrs:


s.sendto(roomDescr,(u,CLIENT_PORT))



def roomDesc():


print 'u r in a green room. the objects in the room, are...', roomDict.items



while True:


try:


# creates a connection socket, pop into clientele list.


(clisock, address) = srvrsock.accept()


clientel
e.append(clisock)


clisock.setblocking(0)


#i want the address, don't i...? or is each username going to be


# contained with the clisock


except:


pass


unspecData=[]


for q in clientele:


try:


datas
=q.recv(1024)


if datas!="" and datas != None:


unspecData.append(datas)


except:


pass


#loop through clientele list, send any mesages in mesg list, to all cliens.


#i don't want to send messages, i want t
o broadcast the room description


#how am i going to pick out individual clientele. why is it a list, and not


# a dictionary, anyway. i'm going to change clientele to a dictionary, and


#use the address as a key. how do i get the key...from data, address=q.recv...


# pos i can keep the client list, and add a separate dictionary of users.


#what's the difference.




for q in clientele:


for m in msgs:


q.s
end(m)



#i want to send an inv update to any client that picked up an obj.


#perhaps i should handle that under a section for when that happens.


for q in clientele:


q.close()



-------------------------------------------
------------------------------------------------------------


'''try to start off the database for the MUD.'''


from pysqlite2 import dbapi2 as sqlite

class dbase(object):


def db(self, quay, descr, request):


con=sqlite.connect(":memory:")



con.execute("create table objects(quay varchar, descr varchar")


cur=con.cursor()


objaray=(


('table', 'a table stands in the middle of the room'),


('apple', 'an apple lies on the table'),


)


for o in objaray:


cur.execute("insert into objects (quay,descr) values (?,?)",o)


con.commit()


cur.execute('Select request from objects')


#try and assign this to a varibable


reqestedData=cur.fetchall



cur.close()


con.close()



'''

questions in my mind, are, how do i get other fields to create subobjects,

like the lockpick in the vase.

do i need a seperate database for the rooms. or can't i just put everything into

1 dbase, and just have field
s indicating whether it a room or not.

'''

------------------------------------------------------------------------------------------------

# try to start the framework for the client

#!/usr/bin/python

import socket

HOST = "127.0.0.1"

PORT = 50007


snep=so
cket.socket(socket.AF_INET, socket.SOCK_DGRAM)


while True:


dats=raw_input("debug>")


snep.sendto(dats, (HOST,PORT))


if dats=="quit": break


snep.close()


------------------------------------------------------------------------------------------

OVERALL PLAN FOR THE WORKINGS OF A SUD

An SUD will have:
-


a player

an inventory list

an objects list


the objects will be shared between them. so i will just shuttle the objects back

and forward from one list to the other.

they will need descriptions. th
erefore, the list will have to be a dictionary.


a room or 2.


i need to store the players location, within one of the rooms.


#function_name.has_key(key
-
name)

#It returns TRUE

#if the dictionary has key
-
name in it

#but returns FALSE if it doesn't.


so the

player needs a name, a location.


start off with rooms.

i am gonna try to make a dictionary with a variable 'key'

maybe i should use UNIONS and such, to see if an item is in 2 lists....

'''



#start it off as empty, and add to it, whenever

roomDict={
'painting': 'a constable painting hangs on the wall',


'carpet': 'the carpet is faded and jaded',


'cupboard':'why there has to be a cupboard in a room, i do not know, but, unoriginally, there is',


'vase':'tra la la. ther
e would just happen to be a vase sat on the cupboard. prob got a key inside. why not
have a look.'}

#possibly have a dictionary contatiaing ALL the objects, wherever they may be....

allObjects={}


inv={'rucksack':' you have got nada inside the bag. nada!'
}


#for t in roomDict

print "you are in a room. inside, is a", roomDict.keys()

print "type in an items name to examine it"

i=raw_input()

for i in roomDict:


if roomDict.has_key(i):


print roomDict[i];


else:


print 'pla'