march
2007年12月11日 18:13
#libsecondlifeのロード
import clr
clr.AddReferenceToFile("libsecondlife.dll")
import libsecondlife
import time
#ログイン情報の設定
firstName = 'abcd' #苗字
lastName = 'efgh' #名前
passWord = 'ijkl' #パスワード
#イベント待ち合わせ用クラスの定義
class EventTracker:
def __init__(self):
self.data=False
def Clear(self):
self.data=False
def Set(self):
self.data=True
def Wait(self):
while not self.data:
time.sleep(0.1)
#チャットイベント処理用ハンドラの定義
def chatHandler(message, hearRange, chatType, chatSourceType, agentName, uuid1, uuid2, locationVector):
print 'message =', message
print 'hearRange =', hearRange
print 'chatType =', chatType #StartTyping, Normal, StopTyping
print 'chatsourceType =', chatSourceType
print 'agentName =', agentName
print 'uuid1 =', uuid1 #SourceID?
print 'uuid2 =', uuid2 #OwnerID?
print 'locationVector =', locationVector
#IM受信イベント処理用のハンドラの定義
def instantMessageHandler(im, sim):
print 'sim=', sim.ToString()
attrList = [
'ToAgentID',
'FromAgentID',
'FromAgentName',
'ParentEstateID',
'RegionID',
'Position',
'Dialog',
'GroupIM',
'IMSessionID',
'Timestamp',
'Message',
'Offline',
'BinaryBucket'
]
for i in attrList:
print i, '=', eval('im.%s' % (i) )
#初期設定
event = EventTracker()
client = libsecondlife.SecondLife()
client.Self.OnChat += libsecondlife.AgentManager.ChatCallback(chatHandler)
client.Self.OnInstantMessage += libsecondlife.AgentManager.InstantMessageCallback(instantMessageHandler)
#接続
client.Network.Login(firstName, lastName, passWord, '', '')
time.sleep(10)
#実際の処理
#現在時刻をチャットで発言する
msg = 'now ' + time.strftime('%Y-%m-%d %H:%M:%S')
chatType = libsecondlife.ChatType.Normal #ChatType.Say is obsolete version and will likely be removed in the near future.
client.Self.Chat(msg, 0, chatType)
time.sleep(10)
#自分自身にIMを送信する
targetUuid = client.Self.AgentID
msg = 'now ' + time.strftime('%Y-%m-%d %H:%M:%S')
client.Self.InstantMessage(targetUuid, msg)
time.sleep(10)
#切断
client.Network.Logout()