diff --git a/pyogp/lib/base/tests/legacy/presence_code.py b/pyogp/lib/base/tests/legacy/presence_code.py
new file mode 100644
index 0000000..1c911a0
--- /dev/null
+++ b/pyogp/lib/base/tests/legacy/presence_code.py
@@ -0,0 +1,373 @@
+#!/usr/bin/python
+"""
+@file presence_code.py
+@author Lawson English
+@date 2008-06-13
+@brief Iniitializes path directories
+
+$LicenseInfo:firstyear=2008&license=apachev2$
+
+Copyright 2008, Linden Research, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+$/LicenseInfo$
+"""
+
+from struct import *
+from zerocode import *
+import md5
+import xmlrpclib
+import sys
+
+import re
+import httplib, urllib
+from urlparse import urlparse
+import socket, sys, time
+import uuid
+from makepacketdict import makepacketdict
+
+
+
+from datetime import datetime
+
+
+mypacketdictionary = {}
+outputstring = ''
+ack_need_list = []
+
+MAC = '00:00:00:00:00:00'
+
+logoutputflag = False
+
+if logoutputflag:
+ temp = sys.stdout
+ sys.stdout =open('alog.txt','w')
+
+def login(first, last, passwd, mac):
+ passwd_md5 = '$1$' + md5.new(passwd).hexdigest()
+
+ uri = 'http://127.0.0.1'
+ uri = 'https://login.aditi.lindenlab.com/cgi-bin/login.cgi'
+ s = xmlrpclib.ServerProxy(uri)
+
+ login_details = {
+ 'first': first,
+ 'last': last,
+ 'passwd': passwd_md5,
+ #'start': 'last',
+ 'start': 'uri:Hazzard County&141&33&35',
+ 'major': '1',
+ 'minor': '18',
+ 'patch': '5',
+ 'build': '3',
+ 'platform': 'Win',
+ 'mac': mac,
+ 'options': [],
+ 'user-agent': 'sl.py 0.1',
+ 'id0': '',
+ 'agree_to_tos': '',
+ 'viewer_digest': '09d93740-8f37-c418-fbf2-2a78c7b0d1ea',
+ 'version': '1.0.0'
+ }
+ results = s.login_to_simulator(login_details)
+ print results
+
+ return results
+
+
+
+
+def get_caps(results,cap_key, request_keys):
+
+ _, netloc, path, _, _, _ = urlparse(results[cap_key])
+
+ params = ""+ request_keys[0]+""
+ headers = {"content-type": "application/xml"}
+ conn = httplib.HTTPSConnection(netloc)
+
+ conn.request("POST", path, params, headers)
+ response = conn.getresponse()
+
+
+ data = response.read()
+ conn.close()
+ return data
+
+def ExtractCap(cap_result):
+ trim_xml = re.compile(r"([a-zA-Z_]+)([a-zA-Z_:/0-9-.]+)")
+ new_key = trim_xml.search(cap_result).group(1)
+ new_cap = trim_xml.search(cap_result).group(2)
+ return new_key, new_cap
+
+
+
+def scheduleacknowledgemessage(data):
+ if not (ord(data[0])&0x40):
+ print "OOOPS! Got asked to ack a message that shouldn't be acked"
+
+ return
+ else:
+ ID = data[1:5]
+ if (ord(data[0])&0x40) & 0x80: ID = zero_decode_ID(ID)
+ ack_need_list.append(unpack(">L",ID)[0])
+ #ack_need_list.append(unpack(">L",data[1:5])[0])
+ #print "ack needed","insdie schedule ack_need_list", ack_need_list
+
+
+ return
+
+def packacks():
+ acksequence = ""
+ for msgnum in ack_need_list:
+ acksequence = acksequence + pack("0:
+
+
+#===============================================================================
+# {
+# UUIDNameRequest Low NotTrusted Unencoded
+# {
+# UUIDNameBlock Variable
+# { ID LLUUID }
+# }
+# }
+#===============================================================================
+
+def sendUUIDNameRequest(sock, port, host, currentsequence,aUUID):
+
+ packed_data = ""
+ fix_ID = int("0xffff0000",16)+ 235
+ data_header = pack('>BLB', 0x00,currentsequence,0x00)
+
+
+ for i in range(len(aUUID)):
+ packed_data = packed_data+uuid.UUID(aUUID[i]).bytes
+
+ packed_data = data_header + pack("L",fix_ID) + pack(">B",len(aUUID)) + packed_data
+
+ sock.sendto(packed_data, (host, port))
+ return
+
+def sendRegionHandshakeReply(sock, port, host, currentsequence,agentUUID,sessionUUID):
+ packed_data = ""
+
+ low_ID = "0xffff00%2x" % 149
+ data_header = pack('>BLB', 0x00,currentsequence,0x00)
+ packed_data = packed_data+uuid.UUID(agentUUID).bytes+uuid.UUID(sessionUUID).bytes+ pack(">L",0x00)
+ packed_data = data_header + pack(">L",int(low_ID,16))+packed_data
+ sock.sendto(packed_data, (host, port))
+ #print "RegionHandshakeReply", ByteToHex(packed_data)
+ return
+
+
+
+def sendAgentUpdate(sock, port, host, currentsequence, result):
+
+#AgentUpdate
+
+ tempacks = packacks()
+ del ack_need_list[0:]
+ if tempacks == "":
+ flags = 0x00
+ else:
+ flags = 0x10
+
+ #print "tempacks is:", ByteToHex(tempacks)
+
+ data_header = pack('>BLB', flags,currentsequence,0x00)
+ packed_data_message_ID = pack('>B',0x04)
+ packed_data_ID = uuid.UUID(result["agent_id"]).bytes + uuid.UUID(result["session_id"]).bytes
+ packed_data_QuatRots = pack('BLB', 0x00,currentsequence,0x00)
+ packed_data_message_ID = pack('>B',0x02)
+ packed_data = data_header + packed_data_message_ID+pack('>B', lastPingSent)
+ print "CompletePingCheck packet sent:", ByteToHex(packed_data)
+ sock.sendto(packed_data, (host, port))
+
+ return
+
+def sendPacketAck(sock, port, host,currentsequence):
+
+ tempacks = packacks()
+ templen = len(ack_need_list)
+ del ack_need_list[0:]
+ data_header = pack('>BLB',0x00,currentsequence,0x00)
+ packed_data_message_ID = pack('>L',0xFFFFFFFB)
+ packed_ack_len = pack('>B',templen)
+
+ packed_data = data_header + packed_data_message_ID + packed_ack_len + tempacks
+#===============================================================================
+# t = datetime.now()
+# t.strftime("%H:%M:%S")
+# ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+# print ti, "PacketAck packet sent:", ByteToHex(packed_data)
+#===============================================================================
+ sock.sendto(packed_data, (host, port))
+ return
+
+def establishpresence(host, port, circuit_code):
+
+
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+#Sending packet UseCircuitCode <-- Inits the connection to the sim.
+ data = pack('>BLBL',0x00,0x01,00,0xffff0003) + pack('BLBL',0x00,0x02,00,0xffff00f9) + uuid.UUID(result["agent_id"]).bytes + uuid.UUID(result["session_id"]).bytes + pack('L", ID[:4])
+ if ID[0] == '\xFF':
+ if ID[1] == '\xFF':
+ if ID[2] == '\xFF':
+ myentry = mypacketdictionary[("Fixed" , "0x"+ByteToHex(ID[0:4]).replace(' ', ''))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i, "trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("Low",int("0x"+ByteToHex(ID[2:4]).replace(' ', ''),16))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+ if myentry[0] == "UUIDNameReply":
+ pass
+ #print ByteToHex(data)
+ #print data[:28]
+ #print data[28:36],data[38:45]
+ elif myentry[0] == "RegionHandshake":
+ sendRegionHandshakeReply(sock, port, host, seqnum,result["agent_id"],result["session_id"])
+ seqnum += 1
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("Medium", int("0x"+ByteToHex(ID[1:2]).replace(' ', ''),16))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("High", int("0x"+ByteToHex(ID[0]), 16))]
+ if myentry[0] == "StartPingCheck":
+ print "data from StartPingCheck", test
+ sendCompletePingCheck(sock, port, host, seqnum,data,lastPingSent)
+ lastPingSent = lastPingSent+ 1
+ seqnum = seqnum + 1
+
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ sock.close()
+ print "final number of trusted messages =", trusted_count
+
+ return
+
+
+
+
+result = login("Enusbot1", "LLQABot", "lindentest", MAC)
+
+mypacketdictionary = makepacketdict()
+
+myhost = result["sim_ip"]
+myport = result["sim_port"]
+mycircuit_code = result["circuit_code"]
+
+establishpresence(myhost, myport, mycircuit_code)
+
+#cap_out = get_caps(result,"seed_capability", ["ChatSessionRequest"])
diff --git a/pyogp/lib/base/tests/makepacketdict.py b/pyogp/lib/base/tests/makepacketdict.py
new file mode 100644
index 0000000..768d8f3
--- /dev/null
+++ b/pyogp/lib/base/tests/makepacketdict.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+"""
+@file makepacketdict.py
+@author Lawson English
+@date 2008-06-13
+@brief Iniitializes path directories
+
+$LicenseInfo:firstyear=2008&license=apachev2$
+
+Copyright 2008, Linden Research, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+$/LicenseInfo$
+"""
+
+import re
+
+def makepacketdict():
+ dict = {}
+ for line in open("../../release/scripts/messages/message_template.msg", ).xreadlines():
+ results = re.match("^\t([^\t{}]+.+)",line)
+ if results:
+ aline = results.group(1)
+ aline = aline.split()
+ if aline[1] == "Fixed":
+ dict[(aline[1],int("0x"+aline[2][8:],16))] = (aline[0],aline[3], aline[4])
+ else:
+ dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
+ return dict
diff --git a/pyogp/lib/base/tests/pyogp-login.py b/pyogp/lib/base/tests/pyogp-login.py
new file mode 100644
index 0000000..bad6796
--- /dev/null
+++ b/pyogp/lib/base/tests/pyogp-login.py
@@ -0,0 +1,459 @@
+#!/usr/bin/python
+"""
+@file pyogp-login.py
+@author Linden Lab
+@date 2008-06-13
+@brief Iniitializes path directories
+
+$LicenseInfo:firstyear=2008&license=apachev2$
+
+Copyright 2008, Linden Research, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+$/LicenseInfo$
+"""
+
+import sys
+import os.path
+import urllib2
+import md5
+import xmlrpclib
+import re
+import httplib, urllib
+from urlparse import urlparse
+import socket, sys, time
+import uuid
+from struct import *
+
+from datetime import datetime
+
+
+if os.path.exists("../setup_path.py"):
+ execfile("../setup_path.py")
+
+# linden provided libs
+from indra.base import llsd
+from indra.ipc import llsdhttp
+
+# Sai's helpers
+from makepacketdict import makepacketdict
+from zerocode import *
+
+
+
+debug = False
+
+if len(sys.argv) > 1:
+ if sys.argv[1] == '--debug':
+ debug = True
+
+mypacketdictionary = {}
+outputstring = ''
+ack_need_list = []
+
+def main():
+
+ agent = {'password':'somepassword',
+ 'firstname':'somefirstname',
+ 'lastname':'somelastname'}
+ loginuri = 'https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi'
+ regionuri = 'http://sim2.vaak.lindenlab.com:12035'
+ result = login(agent, loginuri, regionuri)
+
+ mypacketdictionary = makepacketdict()
+
+ myhost = result["sim_ip"]
+ myport = result["sim_port"]
+ mycircuit_code = result["circuit_code"]
+ establishpresence(myhost, myport, mycircuit_code, result)
+ #cap_out = get_caps(result,"seed_capability", ["ChatSessionRequest"])
+
+# login to secondlife
+def login(agent, loginuri, regionuri):
+ # post to auth.cgi
+ loginparams={#'type' : 'agent',
+ 'password' : agent['password'], # md5-password '$1$' + md5hash
+ 'lastname' : agent['lastname'],
+ 'firstname' : agent['firstname'],
+ }
+
+ llsdlist = llsd.format_xml(loginparams)
+
+ # print llsdlist
+
+ headers = {"Content-type" : "application/llsd+xml"}
+
+ if debug:
+ print 'Posting the following llsd to loginuri: ' + loginuri
+ print llsdlist
+ print ''
+
+ request = urllib2.Request(loginuri,llsdlist,headers)
+
+
+ class RedirectHandler(urllib2.HTTPRedirectHandler):
+
+ def http_error_302(self, req, fp, code, msg, headers):
+ #ignore the redirect, grabbing the seed cap url from the headers
+ if debug:
+ print ''
+ print 'contents of response = '
+ print headers
+ print msg
+ print ''
+ return headers['location']
+
+
+ # post to auth.cgi, ignoring the built in redirect
+ opener = urllib2.build_opener(RedirectHandler())
+ seed_cap = opener.open(request)
+
+ print 'Holy cow, we\'re logged in!'
+ print 'Seed cap: ' + seed_cap
+
+ # Next we get the place_avatar cap, which we could then call with a regionuri
+
+ pap = {'caps':'place_avatar'}
+ # 'place_avatar':True}
+
+ llsdpap = llsd.format_xml(pap)
+
+ # print llsdpap
+ if debug:
+ print ''
+ print 'Posting the following llsd to the seed_cap url: ' + seed_cap
+ print llsdpap
+ print ''
+
+ request = urllib2.Request(seed_cap, llsdpap, headers)
+ result = urllib2.urlopen(request).read()
+
+ if debug:
+ print ''
+ print 'contents of response'
+ print result
+ print ''
+
+ place_avatar_cap = llsd.parse(result)['caps']['place_avatar']
+
+ print 'Holy cow, we got a place avatar cap: '
+ #print llsd.parse(result)
+ print 'Place avatar cap: ' + place_avatar_cap
+
+ # Next we post to place_avatar cap with a regionuri
+
+ region = {'region_url' : regionuri }
+ llsdregion = llsd.format_xml(region)
+
+ #print llsdregion
+ print 'Posting this llsd to the place avatar cap: ' + place_avatar_cap
+ print llsdregion
+
+ request = urllib2.Request(place_avatar_cap, llsdregion, headers)
+ result = urllib2.urlopen(request).read()
+
+ print 'Holy cow, we can try and get to a sim:'
+ print 'Rez avatar cap: '
+ print llsd.parse(result)
+
+ return llsd.parse(result)
+
+def get_caps(results,cap_key, request_keys):
+
+ _, netloc, path, _, _, _ = urlparse(results[cap_key])
+
+ params = ""+ request_keys[0]+""
+ headers = {"content-type": "application/xml"}
+ conn = httplib.HTTPSConnection(netloc)
+
+ conn.request("POST", path, params, headers)
+ response = conn.getresponse()
+
+
+ data = response.read()
+ conn.close()
+ return data
+
+def ExtractCap(cap_result):
+ trim_xml = re.compile(r"([a-zA-Z_]+)([a-zA-Z_:/0-9-.]+)")
+ new_key = trim_xml.search(cap_result).group(1)
+ new_cap = trim_xml.search(cap_result).group(2)
+ return new_key, new_cap
+
+
+
+def scheduleacknowledgemessage(data):
+ if not (ord(data[0])&0x40):
+ print "OOOPS! Got asked to ack a message that shouldn't be acked"
+
+ return
+ else:
+ ID = data[1:5]
+ if (ord(data[0])&0x40) & 0x80: ID = zero_decode_ID(ID)
+ ack_need_list.append(unpack(">L",ID)[0])
+ #ack_need_list.append(unpack(">L",data[1:5])[0])
+ #print "ack needed","insdie schedule ack_need_list", ack_need_list
+
+
+ return
+
+def packacks():
+ acksequence = ""
+ for msgnum in ack_need_list:
+ acksequence = acksequence + pack("0:
+
+
+#===============================================================================
+# {
+# UUIDNameRequest Low NotTrusted Unencoded
+# {
+# UUIDNameBlock Variable
+# { ID LLUUID }
+# }
+# }
+#===============================================================================
+
+def sendUUIDNameRequest(sock, port, host, currentsequence,aUUID):
+
+ packed_data = ""
+ fix_ID = int("0xffff0000",16)+ 235
+ data_header = pack('>BLB', 0x00,currentsequence,0x00)
+
+
+ for i in range(len(aUUID)):
+ packed_data = packed_data+uuid.UUID(aUUID[i]).bytes
+
+ packed_data = data_header + pack("L",fix_ID) + pack(">B",len(aUUID)) + packed_data
+
+ sock.sendto(packed_data, (host, port))
+ return
+
+def sendRegionHandshakeReply(sock, port, host, currentsequence,agentUUID,sessionUUID):
+ packed_data = ""
+
+ low_ID = "0xffff00%2x" % 149
+ data_header = pack('>BLB', 0x00,currentsequence,0x00)
+ packed_data = packed_data+uuid.UUID(agentUUID).bytes+uuid.UUID(sessionUUID).bytes+ pack(">L",0x00)
+ packed_data = data_header + pack(">L",int(low_ID,16))+packed_data
+ sock.sendto(packed_data, (host, port))
+ #print "RegionHandshakeReply", ByteToHex(packed_data)
+ return
+
+
+
+def sendAgentUpdate(sock, port, host, currentsequence, result):
+
+#AgentUpdate
+
+ tempacks = packacks()
+ del ack_need_list[0:]
+ if tempacks == "":
+ flags = 0x00
+ else:
+ flags = 0x10
+
+ #print "tempacks is:", ByteToHex(tempacks)
+
+ data_header = pack('>BLB', flags,currentsequence,0x00)
+ packed_data_message_ID = pack('>B',0x04)
+ packed_data_ID = uuid.UUID(result["agent_id"]).bytes + uuid.UUID(result["session_id"]).bytes
+ packed_data_QuatRots = pack('BLB', 0x00,currentsequence,0x00)
+ packed_data_message_ID = pack('>B',0x02)
+ packed_data = data_header + packed_data_message_ID+pack('>B', lastPingSent)
+ print "CompletePingCheck packet sent:", ByteToHex(packed_data)
+ sock.sendto(packed_data, (host, port))
+
+ return
+
+def sendPacketAck(sock, port, host,currentsequence):
+
+ tempacks = packacks()
+ templen = len(ack_need_list)
+ del ack_need_list[0:]
+ data_header = pack('>BLB',0x00,currentsequence,0x00)
+ packed_data_message_ID = pack('>L',0xFFFFFFFB)
+ packed_ack_len = pack('>B',templen)
+
+ packed_data = data_header + packed_data_message_ID + packed_ack_len + tempacks
+#===============================================================================
+# t = datetime.now()
+# t.strftime("%H:%M:%S")
+# ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+# print ti, "PacketAck packet sent:", ByteToHex(packed_data)
+#===============================================================================
+ sock.sendto(packed_data, (host, port))
+ return
+
+def sendLogoutRequest(sock, port, host,seqnum,aUUID,sUUID):
+ packed_data = ""
+ packed_data_message_ID = pack('>L',0xffff00fc)
+ data_header = pack('>BLB', 0x00,seqnum,0x00)
+ packed_data = packed_data+uuid.UUID(aUUID).bytes+uuid.UUID(sUUID).bytes+ pack(">L",0x00)
+
+ packed_data = data_header + packed_data_message_ID + packed_data
+ sock.sendto(packed_data, (host, port))
+ return
+
+
+def establishpresence(host, port, circuit_code, result):
+
+
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+#Sending packet UseCircuitCode <-- Inits the connection to the sim.
+ data = pack('>BLBL',0x00,0x01,00,0xffff0003) + pack('BLBL',0x00,0x02,00,0xffff00f9) + uuid.UUID(result["agent_id"]).bytes + uuid.UUID(result["session_id"]).bytes + pack('L", ID[:4])
+ if ID[0] == '\xFF':
+ if ID[1] == '\xFF':
+ if ID[2] == '\xFF':
+ myentry = mypacketdictionary[("Fixed" , "0x"+ByteToHex(ID[0:4]).replace(' ', ''))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i, "trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("Low",int("0x"+ByteToHex(ID[2:4]).replace(' ', ''),16))] # ,16
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+ if myentry[0] == "UUIDNameReply":
+ pass
+ #print ByteToHex(data)
+ #print data[:28]
+ #print data[28:36],data[38:45]
+ elif myentry[0] == "RegionHandshake":
+ sendRegionHandshakeReply(sock, port, host, seqnum,result["agent_id"],result["session_id"])
+ seqnum += 1
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("Medium", int("0x"+ByteToHex(ID[1:2]).replace(' ', ''),16))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("High", int("0x"+ByteToHex(ID[0]), 16))]
+ if myentry[0] == "StartPingCheck":
+ print "data from StartPingCheck", test
+ sendCompletePingCheck(sock, port, host, seqnum,data,lastPingSent)
+ lastPingSent = lastPingSent+ 1
+ seqnum = seqnum + 1
+
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ '''
+ sendLogoutRequest(sock, port, host,seqnum,myAgentID,mySessionID)
+
+ sock.close()
+ print "final number of trusted messages =", trusted_count
+
+ return
+
+
+if __name__ == "__main__":
+ main()
+
diff --git a/pyogp/lib/base/tests/pyogp.lib-login.py b/pyogp/lib/base/tests/pyogp.lib-login.py
new file mode 100644
index 0000000..753c213
--- /dev/null
+++ b/pyogp/lib/base/tests/pyogp.lib-login.py
@@ -0,0 +1,410 @@
+#!/usr/bin/python
+"""
+@file pyogp.lib-login.py
+@author Linden Lab
+@date 2008-06-13
+@brief Iniitializes path directories
+
+$LicenseInfo:firstyear=2008&license=apachev2$
+
+Copyright 2008, Linden Research, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+$/LicenseInfo$
+"""
+
+import sys, struct
+import os.path
+import urllib2
+import md5
+import xmlrpclib
+import re
+from urlparse import urlparse
+import socket, sys, time
+import uuid
+from struct import *
+from optparse import OptionParser
+import pprint
+
+from datetime import datetime
+
+
+if os.path.exists("../setup_path.py"):
+ execfile("../setup_path.py")
+
+# linden provided libs
+from indra.base import llsd
+from indra.ipc import llsdhttp
+from indra.base import lluuid
+
+# lib classes
+from pyogp.lib.agent import Agent
+from pyogp.client.ogplogin import OGPLogin
+from pyogp.lib.capabilities import Capabilities
+
+# Sai's helpers
+from makepacketdict import makepacketdict
+from zerocode import *
+
+# defaults for the purpose of this test script
+debug = True
+
+mypacketdictionary = {}
+outputstring = ''
+ack_need_list = []
+
+def main():
+
+ (options) = process_options()
+
+ agent = Agent()
+
+ agent.setLoginParams(options.firstname, options.lastname, options.password, None, options.loginuri, options.regionuri)
+
+ if debug:
+ print 'Posting the following llsd to ' + agent.loginuri
+ print agent.getLoginParams()
+
+ login = OGPLogin(agent)
+ result = login.login()
+
+ if result == None:
+ print 'Couldn"t log in.'
+ return
+
+ myhost = result['sim_ip']
+ myport = result['sim_port']
+ mycircuit_code = result['circuit_code']
+
+ establishpresence(myhost, myport, mycircuit_code, result)
+
+ #cap_out = get_caps(result,"seed_capability", ["ChatSessionRequest"])
+
+def process_options():
+
+ parser = OptionParser(usage="pyogp.lib-login.py --firstname [firstname] --lastname [lastname] --password [password]")
+ parser.add_option("--firstname", dest="firstname", help="firstname of the agent to login to the agent domain")
+ parser.add_option("--lastname", dest="lastname", help="lastname")
+ parser.add_option("--password", dest="password", help="password - not md5 for now")
+ parser.add_option("--md5pass", dest="md5pass", help="inactive md5 placeholder", default=None)
+ parser.add_option("--loginuri", dest="loginuri", help="loginuri to authenticate against", default='https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi')
+ parser.add_option("--regionuri", dest="regionuri", help="regionuri of the simulator to connect to", default='http://sim1.vaak.lindenlab.com:13000')
+ options, args = parser.parse_args()
+
+ if not options.firstname:
+ print "ERROR: --firstname is required"
+ print parser.get_usage()
+ sys.exit(-1)
+
+ if not options.lastname:
+ print "ERROR: --lastname is required"
+ print parser.get_usage()
+ sys.exit(-1)
+
+ if not options.password:
+ print "ERROR: --password is required"
+ print parser.get_usage()
+ sys.exit(-1)
+
+
+ return options
+def get_caps(results,cap_key, request_keys):
+
+ _, netloc, path, _, _, _ = urlparse(results[cap_key])
+
+ params = ""+ request_keys[0]+""
+ headers = {"content-type": "application/xml"}
+ conn = httplib.HTTPSConnection(netloc)
+
+ conn.request("POST", path, params, headers)
+ response = conn.getresponse()
+
+
+ data = response.read()
+ conn.close()
+ return data
+
+def ExtractCap(cap_result):
+ trim_xml = re.compile(r"([a-zA-Z_]+)([a-zA-Z_:/0-9-.]+)")
+ new_key = trim_xml.search(cap_result).group(1)
+ new_cap = trim_xml.search(cap_result).group(2)
+ return new_key, new_cap
+
+
+
+def scheduleacknowledgemessage(data):
+ if not (ord(data[0])&0x40):
+ print "OOOPS! Got asked to ack a message that shouldn't be acked"
+
+ return
+ else:
+ ID = data[1:5]
+ if (ord(data[0])&0x40) & 0x80: ID = zero_decode_ID(ID)
+ ack_need_list.append(unpack(">L",ID)[0])
+ #ack_need_list.append(unpack(">L",data[1:5])[0])
+ #print "ack needed","insdie schedule ack_need_list", ack_need_list
+
+
+ return
+
+def packacks():
+ acksequence = ""
+ for msgnum in ack_need_list:
+ acksequence = acksequence + pack("0:
+
+
+#===============================================================================
+# {
+# UUIDNameRequest Low NotTrusted Unencoded
+# {
+# UUIDNameBlock Variable
+# { ID LLUUID }
+# }
+# }
+#===============================================================================
+
+def sendUUIDNameRequest(sock, port, host, currentsequence,aUUID):
+
+ packed_data = ""
+ fix_ID = int("0xffff0000",16)+ 235
+ data_header = pack('>BLB', 0x00,currentsequence,0x00)
+
+
+ for i in range(len(aUUID)):
+ packed_data = packed_data+uuid.UUID(aUUID[i]).bytes
+
+ packed_data = data_header + pack("L",fix_ID) + pack(">B",len(aUUID)) + packed_data
+
+ sock.sendto(packed_data, (host, port))
+ return
+
+def sendRegionHandshakeReply(sock, port, host, currentsequence,agentUUID,sessionUUID):
+ packed_data = ""
+
+ low_ID = "0xffff00%2x" % 149
+ data_header = pack('>BLB', 0x00,currentsequence,0x00)
+ packed_data = packed_data+uuid.UUID(agentUUID).bytes+uuid.UUID(sessionUUID).bytes+ pack(">L",0x00)
+ packed_data = data_header + pack(">L",int(low_ID,16))+packed_data
+ sock.sendto(packed_data, (host, port))
+ #print "RegionHandshakeReply", ByteToHex(packed_data)
+ return
+
+
+
+def sendAgentUpdate(sock, port, host, currentsequence, result):
+
+#AgentUpdate
+
+ tempacks = packacks()
+ del ack_need_list[0:]
+ if tempacks == "":
+ flags = 0x00
+ else:
+ flags = 0x10
+
+ #print "tempacks is:", ByteToHex(tempacks)
+
+ data_header = pack('>BLB', flags,currentsequence,0x00)
+ packed_data_message_ID = pack('>B',0x04)
+ packed_data_ID = uuid.UUID(result["agent_id"]).bytes + uuid.UUID(result["session_id"]).bytes
+ packed_data_QuatRots = pack('BLB', 0x00,currentsequence,0x00)
+ packed_data_message_ID = pack('>B',0x02)
+ packed_data = data_header + packed_data_message_ID+pack('>B', lastPingSent)
+ print "CompletePingCheck packet sent:", ByteToHex(packed_data)
+ sock.sendto(packed_data, (host, port))
+
+ return
+
+def sendPacketAck(sock, port, host,currentsequence):
+
+ tempacks = packacks()
+ templen = len(ack_need_list)
+ del ack_need_list[0:]
+ data_header = pack('>BLB',0x00,currentsequence,0x00)
+ packed_data_message_ID = pack('>L',0xFFFFFFFB)
+ packed_ack_len = pack('>B',templen)
+
+ packed_data = data_header + packed_data_message_ID + packed_ack_len + tempacks
+#===============================================================================
+# t = datetime.now()
+# t.strftime("%H:%M:%S")
+# ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+# print ti, "PacketAck packet sent:", ByteToHex(packed_data)
+#===============================================================================
+ sock.sendto(packed_data, (host, port))
+ return
+
+def sendLogoutRequest(sock, port, host,seqnum,aUUID,sUUID):
+ packed_data = ""
+ packed_data_message_ID = pack('>L',0xffff00fc)
+ data_header = pack('>BLB', 0x00,seqnum,0x00)
+ packed_data = packed_data+uuid.UUID(aUUID).bytes+uuid.UUID(sUUID).bytes+ pack(">L",0x00)
+
+ packed_data = data_header + packed_data_message_ID + packed_data
+ sock.sendto(packed_data, (host, port))
+ return
+
+
+def establishpresence(host, port, circuit_code, result):
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+#Sending packet UseCircuitCode <-- Inits the connection to the sim.
+ data = pack('>BLBL',0x00,0x01,00,0xffff0003) + pack('BLBL',0x00,0x02,00,0xffff00f9) + uuid.UUID(result["agent_id"]).bytes + uuid.UUID(result["session_id"]).bytes + pack(' 30:
+ # break
+
+ '''
+ if not data:
+ print "Client has exited!"
+
+ break
+ else:
+ pass
+ test = ByteToHex(data).split()
+ #print test
+ ID = data[6:12]
+ #print "ID =", ByteToHex(ID)
+ if (ord(data[0])&0x80):
+ ID = zero_decode_ID(data[6:12])
+
+ if (ord(data[0])&0x40):
+ scheduleacknowledgemessage(data);
+ ack_need_list_changed = True
+ #print "ID =", ByteToHex(ID)
+ #print "ID =", unpack(">L", ID[:4])
+ if ID[0] == '\xFF':
+ if ID[1] == '\xFF':
+ if ID[2] == '\xFF':
+ myentry = mypacketdictionary[("Fixed" , "0x"+ByteToHex(ID[0:4]).replace(' ', ''))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i, "trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("Low",int("0x"+ByteToHex(ID[2:4]).replace(' ', ''),16))] # ,16
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+ if myentry[0] == "UUIDNameReply":
+ pass
+ #print ByteToHex(data)
+ #print data[:28]
+ #print data[28:36],data[38:45]
+ elif myentry[0] == "RegionHandshake":
+ sendRegionHandshakeReply(sock, port, host, seqnum,result["agent_id"],result["session_id"])
+ seqnum += 1
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("Medium", int("0x"+ByteToHex(ID[1:2]).replace(' ', ''),16))]
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ else:
+ myentry = mypacketdictionary[("High", int("0x"+ByteToHex(ID[0]), 16))]
+ if myentry[0] == "StartPingCheck":
+ print "data from StartPingCheck", test
+ sendCompletePingCheck(sock, port, host, seqnum,data,lastPingSent)
+ lastPingSent = lastPingSent+ 1
+ seqnum = seqnum + 1
+
+ if myentry[1] == "Trusted":
+ trusted += 1;
+ ti = "%02d:%02d:%02d.%06d" % (t.hour,t.minute,t.second,t.microsecond)
+
+ print ti, "Message #", i,"trusted count is", trusted,"Flags: 0x" + test[0], myentry, "sequence #", unpack(">L",data[1:5])
+
+ #if myentry[1] == "Trusted": trusted_count = trusted_count +1;print "number of trusted messages =", trusted_count
+ #if (ord(data[0])&0x40) and (myentry[1] == "Trusted"): trusted_and_ackable = trusted_and_ackable + 1; print "trusted_and_ackable =", trusted_and_ackable
+ #if (ord(data[0])&0x40): ackable = ackable + 1; print "number of ackable messages = ", ackable
+ '''
+ sendLogoutRequest(sock, port, host,seqnum,myAgentID,mySessionID)
+
+ sock.close()
+ print "final number of trusted messages =", trusted_count
+
+ return
+
+
+if __name__ == "__main__":
+ main()
+
diff --git a/pyogp/lib/base/tests/zerocode.py b/pyogp/lib/base/tests/zerocode.py
new file mode 100644
index 0000000..4f7df12
--- /dev/null
+++ b/pyogp/lib/base/tests/zerocode.py
@@ -0,0 +1,130 @@
+#!/usr/bin/python
+"""
+@file zerocode.py
+@author Lawson English
+@date 2008-06-13
+@brief Iniitializes path directories
+
+$LicenseInfo:firstyear=2008&license=apachev2$
+
+Copyright 2008, Linden Research, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+$/LicenseInfo$
+"""
+
+# From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/510399
+# From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/510399
+def ByteToHex( byteStr ):
+ """
+ Convert a byte string to it's hex string representation e.g. for output.
+ """
+
+ # Uses list comprehension which is a fractionally faster implementation than
+ # the alternative, more readable, implementation below
+ #
+ # hex = []
+ # for aChar in byteStr:
+ # hex.append( "%02X " % ord( aChar ) )
+ #
+ # return ''.join( hex ).strip()
+
+ return ''.join( [ "%02X " % ord( x ) for x in byteStr ] ).strip()
+
+
+def HexToByte( hexStr ):
+ """
+ Convert a string hex byte values into a byte string. The Hex Byte values may
+ or may not be space separated.
+ """
+ # The list comprehension implementation is fractionally slower in this case
+ #
+ # hexStr = ''.join( hexStr.split(" ") )
+ # return ''.join( ["%c" % chr( int ( hexStr[i:i+2],16 ) ) \
+ # for i in range(0, len( hexStr ), 2) ] )
+
+ bytes = []
+
+ hexStr = ''.join( hexStr.split(" ") )
+
+ for i in range(0, len(hexStr), 2):
+ bytes.append( chr( int (hexStr[i:i+2], 16 ) ) )
+
+ return ''.join( bytes )
+
+
+def zero_encode(inputbuf):
+ newstring =""
+ zero = False
+ zero_count = 0
+ for c in inputbuf:
+ if c != '\0':
+ if zero_count != 0:
+ newstring = newstring + chr(zero_count)
+ zero_count = 0
+ zero = False
+
+ newstring = newstring + c
+
+ else:
+ if zero == False:
+ newstring = newstring + c
+ zero = True
+
+ zero_count = zero_count + 1
+ if zero_count != 0:
+ newstring = newstring + chr(zero_count)
+
+
+ return newstring
+
+def zero_decode(inputbuf):
+ newstring =""
+ in_zero = False
+ for c in inputbuf:
+ if c != '\0':
+ if in_zero == True:
+ zero_count = ord(c)
+ zero_count = zero_count -1
+ while zero_count>0:
+
+ newstring = newstring + '\0'
+ zero_count = zero_count -1
+ in_zero = False
+ else:
+ newstring = newstring + c
+ else:
+ newstring = newstring + c
+ in_zero = True
+ return newstring
+
+def zero_decode_ID(inputbuf):
+ newstring =""
+ in_zero = False
+ #print "in encode, input is", ByteToHex(inputbuf)
+ for c in inputbuf:
+ if c != '\0':
+ if in_zero == True:
+ zero_count = ord(c)
+ zero_count = zero_count -1
+ while zero_count>0:
+
+ newstring = newstring + '\0'
+ zero_count = zero_count -1
+ in_zero = False
+ else:
+ newstring = newstring + c
+ else:
+ newstring = newstring + c
+ in_zero = True
+ return newstring[:4]