Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- code generated by Win32Lib IDE v0.21.1 Build Sept-29-2006
- constant TheProgramType="exw"
- include Win32Lib.ew
- without warning
- --------------------------------------------------------------------------------
- -- Window Window1
- constant Window1 = createEx( Window, "rotmg client 13.2", 0, Default, Default, 800, 600, 0, 0 )
- sequence IDEFlags
- IDEFlags = classDefaults( Window, { {1, {WS_SYSMENU}},{2, {0}} } )
- constant CWindow1 = createEx( Window, "", Window1, 0, 0, 320, 180, w32or_all({WS_CHILD, WS_CLIPSIBLINGS}), 0 )
- openWindow(CWindow1, Normal)
- moveZOrder( CWindow1, HWND_TOP)
- ---------------------------------------------------------
- --------------------------------------------------------------------------------
- include SrvSckIP.ew
- include ARCFOUR.EW
- include ARCFOUR2.EW
- include euallegro.ew as allegro
- constant space3dto2d=32
- function real(sequence string)
- sequence temp
- temp=value(string)
- return temp[2]
- end function
- procedure centerwindow(integer win)
- integer width,height,window_width,window_height
- sequence size
- size=getCtlSize(win)
- window_width=size[1]
- window_height=size[2]
- width=w32Func(xGetSystemMetrics,{SM_CXSCREEN})
- height=w32Func(xGetSystemMetrics,{SM_CYSCREEN})
- setRect( win,floor((width/2))-floor((window_width/2)) ,floor((height/2))-floor((window_height/2))-32, window_width, window_height, 0 )
- end procedure
- function rgb2( integer r, integer g, integer b )
- return makecol(r,g,b)
- end function
- sequence key_buffer
- key_buffer={}
- function remove_line(sequence string, integer line)
- sequence temp
- integer len
- len=length(string)
- if line=1 then
- return string[2..len]
- elsif line=len then
- return string[1..len-1]
- else
- temp=string[1..line-1]
- return temp&string[line+1..len]
- end if
- end function
- procedure key_add(integer scancode)
- integer found
- found=0
- for i=1 to length(key_buffer) do
- if key_buffer[i]=scancode then
- found=1
- exit
- end if
- end for
- if found=0 then
- key_buffer=append(key_buffer,scancode)
- end if
- end procedure
- procedure key_remove(integer scancode)
- for i=1 to length(key_buffer) do
- if key_buffer[i]=scancode then
- key_buffer=remove_line(key_buffer,i)
- exit
- end if
- end for
- end procedure
- function key_check(integer scancode)
- for i=1 to length(key_buffer) do
- if key_buffer[i]=scancode then
- return 1
- end if
- end for
- return 0
- end function
- constant window_titlebar_height = getSystemMetrics ( SM_CYCAPTION )
- constant window_menu_height = getSystemMetrics ( SM_CYMENU )
- constant window_hscrollbar_width = getSystemMetrics ( SM_CXVSCROLL )
- constant window_vscrollbar_height = getSystemMetrics ( SM_CYVSCROLL )
- constant window_border_width = getSystemMetrics ( SM_CXFRAME )
- constant window_border_height = getSystemMetrics ( SM_CYFRAME )
- constant window_toolbar_height = 33
- constant window_all_height=window_titlebar_height+window_menu_height+window_toolbar_height+(getSystemMetrics ( SM_CYFRAME )*2)
- function convert3dspaceto2d(atom v)
- sequence float
- integer haspoint,leftside,padleft,padright
- atom rightside
- haspoint=0
- float=sprint(v)
- for i=1 to length(float) do
- if float[i]='.' then
- haspoint=1
- leftside=real(float[1..i-1])
- rightside=real("0."&float[i+1..length(float)])
- end if
- end for
- if haspoint=1 then
- padleft=floor(space3dto2d*leftside)
- padright=floor(space3dto2d*rightside)
- return padleft+padright
- else
- return space3dto2d*v
- end if
- end function
- --================================setup allegro============================--
- atom temp_bitmap
- sequence player_bitmaps,tile_bitmaps
- atom the_palette
- atom buffer
- object ret
- integer window_width,window_height,workspace_width,workspace_height
- integer view_left,view_top
- atom color_white,color_black,color_pink,color_green,color_blue,color_red,color_background
- buffer=0
- window_width=800
- window_height=600
- workspace_width=4000
- workspace_height=4000
- view_left=0
- view_top=0
- player_bitmaps={}
- tile_bitmaps={}
- sequence text_sizes
- integer pixelh
- procedure startup_allegro()
- integer ret
- win_set_window(getHWND(Window1))
- the_palette = allocate_palette()
- if allegro_init()!= 0 then
- puts(1,"init\n")
- end if
- if install_timer()!= 0 then
- puts(1,"timer\n")
- end if
- ret=reserve_voices (1, -1)
- if install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, "")!= 0 then
- puts(1,"install sound\n")
- end if
- set_color_depth(16)
- set_palette(the_palette)
- color_white=rgb2(255,255,255)
- color_black=rgb2(0,0,0)
- color_pink=rgb2(255,0,255)
- color_green=rgb2(0,255,0)
- color_blue=rgb2(0,0,255)
- color_red=rgb2(255,0,0)
- color_background=color_white--rgb2(239,235,214)
- temp_bitmap=load_bitmap("images\\players.bmp", the_palette)
- for i=1 to 294 do
- player_bitmaps&=create_bitmap(space3dto2d,space3dto2d)
- blit(temp_bitmap,player_bitmaps[length(player_bitmaps)],(space3dto2d*i)-space3dto2d,0,0,0,space3dto2d,space3dto2d)
- end for
- tile_bitmaps&=load_bitmap("images\\tile1.bmp", the_palette)
- tile_bitmaps&=load_bitmap("images\\tile2.bmp", the_palette)
- tile_bitmaps&=load_bitmap("images\\tile3.bmp", the_palette)
- buffer=create_bitmap(window_width,window_height)
- clear_to_color(buffer,color_background)
- text_sizes=repeat(0,1024)
- for i=32 to 127 do
- text_sizes[i]=text_length(font,sprint(i))/2
- end for
- puts(1,"test "&sprint(text_sizes[32])&"\n")
- pixelh=text_height(font)
- end procedure
- procedure close_allegro()
- destroy_palette(the_palette)
- destroy_bitmap(buffer)
- for i=1 to length(player_bitmaps) do
- destroy_bitmap(player_bitmaps[i])
- end for
- allegro_exit()
- end procedure
- --load_midi
- --play_midi(the_music, 1)
- --play_sample(the_sample, 255, pan, pitch, 1)
- --destroy_midi(the_music)
- --buffer=create_bitmap(view_width,view_height)
- --destroy_bitmap(buffer)
- --load_sample("buzzer.wav")
- --destroy_sample(buzzer_sfx)
- --load_bitmap("marty.bmp", the_palette)
- --================================end setup allegro==========================--
- sequence map_data
- integer map_width,map_height
- map_width=255
- map_height=255
- map_data={}
- --new main loop control
- integer running
- running=1
- atom start_time
- start_time=0
- integer current_tick
- current_tick=0
- integer my_object_id
- my_object_id=0
- sequence my_position
- my_position={}
- sequence my_position_real
- my_position_real={}
- sequence my_status
- my_status={}
- --end main loop control
- sequence my_items,there_items
- my_items={}
- there_items={}
- sequence object_id_to_player_class
- object_id_to_player_class=repeat(0,2000000) --2 million objects
- constant player_constants={806,805,804,803,802,801,800,799,798,797,784,782,775,768}
- sequence player_bitmap_offset
- integer tmp
- player_bitmap_offset=repeat(0,length(player_constants))
- tmp=length(player_constants)
- for i=1 to length(player_constants) do
- player_bitmap_offset[tmp]=(21*(i-1))+8
- tmp-=1
- end for
- include input_stream.ew
- include output_stream.ew
- include location.ew
- include object_status.ew
- include object_status_data.ew
- include stat_data.ew
- include tile.ew
- include players.ew
- constant inputstream = input_stream_new()
- constant outputstream = output_stream_new()
- constant xGetTickCount = registerw32Function(kernel32, "GetTickCount", {}, C_LONG)
- constant xSleep = registerw32Procedure(kernel32, "Sleep", {C_LONG})
- procedure usleep(integer v)
- w32Proc(xSleep,{v})
- end procedure
- function get_tick_count()
- return w32Func(xGetTickCount,{})
- end function
- --public int currentTime() {
- -- return (int) (System.currentTimeMillis() - startTime);
- -- }
- function current_time()
- return w32Func(xGetTickCount,{})-start_time
- end function
- sequence send_buffer
- send_buffer={}
- global constant SM_ASYNC = #FFFF
- atom hWndMainWindow
- atom Server_sock
- constant double_max_value=1.7976931348623157E308
- function create_guest_guid_old()
- atom uid
- uid= 0.6176749197488145--+rand(1073741823)
- return uid*double_max_value
- end function
- function create_guest_guid_java()
- integer fn,char
- sequence data
- fn=open("input.txt","w")
- start_time=get_tick_count()
- puts(fn,sprint(start_time))
- close(fn)
- if system_exec("guest.bat", 2) then
- puts(2, "failure!\n")
- end if
- fn=open("output.txt","rb")
- data=gets(fn)
- close(fn)
- return data
- end function
- function create_login_guid_java(sequence email,sequence pass)
- integer fn,char
- sequence data
- fn=open("input.txt","w")
- puts(fn,email&":"&pass)
- close(fn)
- if system_exec("login.bat", 2) then
- puts(2, "failure!\n")
- end if
- fn=open("output.txt","rb")
- data=gets(fn)
- close(fn)
- for i=1 to length(data) do
- if data[i]=' ' then
- data={data[1..i-1],data[i+1..length(data)]}
- exit
- end if
- end for
- return data
- end function
- procedure debug(sequence text)
- puts(1,text&"\n")
- end procedure
- sequence key1,key2
- --these work
- --key1 is for encrypting data to send to the client
- key1={114,197,88,60,175,182,129,137,149,203,215,75,128}
- --key2 is for decrypting data from the client
- key2={49,31,128,105,20,81,199,27,9,161,58,42,110}
- --finaly got rc4 encrption working 27/03/2013 --update streaming cipher working 03/05/2013
- arcfour_init_encrypt(key1)
- arcfour_init_encrypt2(key2)
- -----------------------------write functions--------------------------------------
- function writeutf(sequence data, sequence v)
- sequence s
- s=int_to_bytes(length(v))
- data&=s[2]&s[1]&v
- return data
- end function
- function writeint(sequence data ,atom v)
- sequence s
- s=int_to_bytes(v)
- data&=s[4]&s[3]&s[2]&s[1]
- return data
- end function
- function writefloat(sequence data ,atom v)
- sequence s
- s = atom_to_float32(v)
- data&=s[4]&s[3]&s[2]&s[1]
- return data
- end function
- function writebool(sequence data, integer b)
- data&=b
- return data
- end function
- function writeshort(sequence data ,atom v)
- sequence s
- s=int_to_bytes(v)
- data&=s[2]&s[1]
- return data
- end function
- function writebyte(sequence data ,integer v)
- data&=v
- return data
- end function
- constant fail_packet=0
- constant useportal_packet=3--USEPORTAL = 3;
- constant ping_packet=6
- constant global_notification_packet=9
- constant tradedone_packet=12--TRADEDONE:int = 12;
- constant shoot_packet=13
- constant hello_packet=17
- constant requesttrade_packet=21--REQUESTTRADE = 21;
- constant tradechanged_packet=23--TRADECHANGED = 23;
- constant text_packet=25 --TEXT
- constant update_packet=26
- constant create_suc_packet=31
- constant create_packet=36
- constant reconnect_packet=39--RECONNECT = 39;
- constant play_sound_packet=44
- constant load_packet=45
- constant accountlist_packet=46
- constant goto_packet=52
- constant show_effect_packet=56
- constant mapinfo_packet=60
- constant traderequest_packet=61 --TRADEREQUESTED = 61;
- constant new_tick_packet=62-- NEW_TICK = 62
- constant notification_packet=63 --NOTIFICATION
- constant tradestart_packet=67--TRADESTART = 67;
- constant allyshoot_packet=74 --ALLYSHOOT
- constant clientstat_packet=75--CLIENTSTAT = 75;
- function hello_packet_write()
- sequence data,temp
- data={}
- data=writeutf(data,"13.2") --build version
- data=writeint(data,-2) --game id
- --data=writeutf(data,"XRU8xQGLzCLaQR2BMOVLE9aPLggIPbNcig/rA1Wyi+KnlfIO02VXKpDEMO7hjscFXccRGOnTHpKoLkbuo2OXrU0wGWzJLsNGSf007Ga71Eu6VCZ61dNIzm71qKl9B5z7ERceI/JFk9NQ7RvmdQpK1s+bB9qAsVWGwhlECBA4EU0=")--create_guest_guid_java())--"PAP6RSeDHDRLpNVO4dw7oMsZS/6gIdnSFj9LHjI/YL8Al61XUPAxMtx5d/fYzmdwbgdRed6X1pHcVKUX16q59wvlzVouQZeim0P8HwXxbuMWwS+Bf9YFUANoriQzjMV/PlNAc17GfxkVQAn2LNYSV3m+BfEAwE6/WUNtyIYZJWI=") --guid
- --data=writeutf(data,"Z+TWxbDpdKsNAKn358XZHOTI4nZEI4/oCrOB7CI8uDYdgWmXN4DKwfCcONgurW+xrGEWoLzviOyg5yRYxaeV55N7OB75OSGtslcs4Tjc8oNRILQG5wofw2YH+MG/jWshUfxC8yQBWJ/Akn+j1ROuS4+CEgjklZjLGC/Oc0EVgDQ=")
- --login deatils
- temp=create_login_guid_java("gdasgdshgdsh@gmail.com","123456")
- data=writeutf(data,temp[1])
- data=writeutf(data,temp[2])
- --puts(1,temp[1]&"\n")
- --puts(1,temp[2]&"\n")
- --guest accoun login
- --data=writeutf(data,create_guest_guid_java())
- --data=writeutf(data,"") --pass
- data=writeutf(data,"") --secert
- data=writeint(data,-1) --key time
- data=writeshort(data,0)
- --data=writebyte(data,0) --
- data=writeint(data,0) --jd length
- --data=writebyte(data,0) -- jd bytes
- data=writeutf(data,"") --pk
- data=writeutf(data,"rotmg") --tq
- data=writeutf(data,"") --h
- data=writeutf(data,"rotmg") --platforum
- data=writeutf(data,"") --unknow
- temp=reverse(int_to_bytes(length(data)+5)) &hello_packet
- data=arcfour_encrypt_block2(data)
- return temp & data
- end function
- --integer map_width,map_height
- sequence map_name
- procedure mapinfo_packet_read()
- object temp
- sequence data
- map_width=input_stream_readint(inputstream)
- map_height=input_stream_readint(inputstream)
- map_name=input_stream_readutf(inputstream)
- temp=input_stream_readint(inputstream)
- temp=input_stream_readint(inputstream)
- temp=input_stream_readbool(inputstream)
- temp=input_stream_readbool(inputstream)
- puts(1,input_stream_get(inputstream)&"\n")
- input_stream_set(inputstream, "")
- map_data={}
- for i=1 to map_height do
- map_data=append(map_data,repeat(0,map_width))
- end for
- --init to zero
- end procedure
- function create_packet_write()
- sequence data,temp
- data={}
- data=writeshort(data,782)
- data=writeshort(data,0)
- temp=reverse(int_to_bytes(length(data)+5)) &create_packet
- data=arcfour_encrypt_block2(data)
- return temp & data
- end function
- function load_packet_write()
- sequence data,temp
- data={}
- data=writeint(data,4)
- temp=reverse(int_to_bytes(length(data)+5)) &45
- data=arcfour_encrypt_block2(data)
- return temp & data
- end function
- function useportal_packet_write(integer num)
- sequence data,temp
- data={}
- data=writeint(data,num)
- temp=reverse(int_to_bytes(length(data)+5)) &useportal_packet
- data=arcfour_encrypt_block2(data)
- return temp & data
- end function
- procedure create_suc_packet_read()
- object res
- puts(1,"create_suc\n")
- my_object_id=input_stream_readint(inputstream)
- ?my_object_id
- --?res
- res=input_stream_readint(inputstream)
- ?res
- --?res
- end procedure
- procedure update_packet_read()
- object res
- integer size,object_type,index
- integer found
- sequence temp,temp2,stats
- --new code optimizeation
- integer object_id
- sequence position
- integer class
- --
- integer fn
- --puts(1,"updated\n")
- size=input_stream_readshort(inputstream)
- --puts(1,"tile size "&sprint(size)&"\n")
- if size!=0 then --tiles
- --fn=open("tiles.txt","w")
- for i=0 to size-1 do
- res=tile_new_from_input(inputstream)
- res=tile_get(res)
- map_data[res[2]][res[1]]=res[3]
- --puts(fn,sprint(tile_get_type(res))&"\n")
- end for
- --for yy=1 to 255 do
- --for xx=1 to 255 do
- --puts(fn,sprint(map_data[yy])&"\n")
- --end for
- --end for
- --close(fn)
- end if
- size=input_stream_readshort(inputstream)
- --puts(1,"newobj size "&sprint(size)&"\n")
- if size!=0 then --new obj
- for i=0 to size-1 do
- res=object_status_new_from_input(inputstream)
- temp=object_status_get(res)
- --?temp[1]--object type
- found=0
- for j=1 to length(player_constants) do
- if temp[1]=player_constants[j] then
- found=j
- end if
- end for
- if found!=0 then
- --my object code--
- temp=object_status_data_get(temp[2])
- --puts(1,sprint(temp[1])&"\n")
- if temp[1]=my_object_id then
- puts(1,"my status updated\n")
- my_position=location_get(temp[2])
- my_position_real=my_position
- for j=1 to length(temp[3]) do
- temp2=stat_data_get(temp[3][j])
- --?temp2
- --if temp2[1]=31 then
- -- puts(1,temp2[3]&"\n")
- -- ?j
- --end if
- my_status=append(my_status,temp2)
- end for
- --?length(my_status)
- --?my_status
- --?location_get(temp[2])
- end if
- -- end my object code
- stats={}
- temp=object_status_data_get(temp[2])
- for j=1 to length(temp[3]) do
- temp2=stat_data_get(temp[3][j])
- stats=append(stats,temp2)
- end for
- --player_list=append(player_list,{temp[1],stats,location_get(temp[2]),found})
- position=location_get(temp[2])
- object_id_to_player_class[temp[1]]=player_new(temp[1],stats,position,found,{convert3dspaceto2d(position[1]),convert3dspaceto2d(position[2])},stats[29][3])
- object_status_delete(res)
- end if
- end for
- end if
- size=input_stream_readshort(inputstream)
- --puts(1,"drop size "&sprint(size)&"\n")
- for i=0 to size-1 do
- res=input_stream_readint(inputstream)
- --new optimize code
- if object_id_to_player_class[res]!=0 then --object to be deleted is a player
- player_delete(object_id_to_player_class[res])
- object_id_to_player_class[res]=0
- end if
- --end new optimized code
- --old code not very fast trying optimzing
- --index=0
- --for j=1 to length(player_list) do
- -- if player_list[j][1]=res then
- -- index=j
- --for k=1 to length(player_list[j][2]) do
- -- if player_list[j][2][k][1]=31 then
- -- puts(1,"player has left "&player_list[j][2][k][3]&"\n")
- -- exit
- -- end if
- -- end for
- -- exit
- -- end if
- --end for
- --if index!=0 then
- -- player_list=remove_line(player_list,index)
- --end if
- --end old code
- end for
- --UPDATEATT = 11;
- temp=reverse(int_to_bytes(length("")+5)) &11
- --write=arcfour_encrypt_block2(write)
- send_buffer=append(send_buffer,{temp})
- end procedure
- procedure global_notification_read()
- object res
- --puts(1,"global_notification \n")
- res=input_stream_readint(inputstream)
- res=input_stream_readutf(inputstream)
- end procedure
- procedure accountlist_read()
- object res
- res=input_stream_readint(inputstream)
- res=input_stream_readshort(inputstream)
- for i=0 to res-1 do
- res=input_stream_readint(inputstream)
- end for
- end procedure
- procedure show_effect_read()
- object res
- res=input_stream_readbyte(inputstream)
- res=input_stream_readint(inputstream)
- res=location_new_from_input(inputstream)
- location_delete(res)
- res=location_new_from_input(inputstream)
- location_delete(res)
- res=input_stream_readint(inputstream)
- end procedure
- procedure allyshoot_read()
- object res
- res=input_stream_readbyte(inputstream)
- res=input_stream_readint(inputstream)
- res=input_stream_readshort(inputstream)
- res=input_stream_readint(inputstream)
- end procedure
- procedure notification_read()
- object res
- res=input_stream_readint(inputstream)
- res=input_stream_readutf(inputstream)
- res=input_stream_readint(inputstream)
- end procedure
- procedure new_tick_read()
- integer size,tick_id
- object res
- sequence temp,write,temp2
- --new code optimizeation
- integer object_id
- sequence position
- integer class
- tick_id=input_stream_readint(inputstream)
- res=input_stream_readint(inputstream)
- size=input_stream_readshort(inputstream)
- for i=0 to size-1 do
- res=object_status_data_new_from_input(inputstream)
- temp=object_status_data_get(res)
- --new optimize code
- object_id=temp[1]
- if object_id_to_player_class[object_id]!=0 then --object to be updated is a player
- position=location_get(temp[2])
- player_update( object_id_to_player_class[object_id],temp[3],position, {convert3dspaceto2d(position[1]),convert3dspaceto2d(position[2]) } )
- end if
- --end new optimized code
- --old code
- --player --stats updae
- --for j=1 to length(player_list) do
- -- if player_list[j][1]=temp[1] then
- -- player_list[j][3]=location_get(temp[2])
- -- for k=1 to length(temp[3]) do
- -- temp2=stat_data_get(temp[3][k])
- -- for l=1 to length(player_list[j][2]) do
- -- if player_list[j][2][l][1]=temp2[1] then
- -- player_list[j][2][l]=temp2
- -- exit
- -- end if
- -- end for
- -- end for
- -- exit
- -- end if
- --end for
- --player stats update--
- --old code
- object_status_data_delete(res)
- end for
- if size!=0 then
- current_tick=tick_id
- end if
- write=""
- write=writeint(write,current_tick) --tick id
- write=writeint(write,current_time()) --time
- --position
- write=writefloat(write,my_position[1])
- write=writefloat(write,my_position[2])
- write=writeshort(write,0)
- --Move = 7;
- temp=reverse(int_to_bytes(length(write)+5)) &7
- write=arcfour_encrypt_block2(write)
- send_buffer=append(send_buffer,{temp&write})
- end procedure
- procedure text_read()
- object res
- integer object_id
- res=input_stream_readutf(inputstream)
- object_id=input_stream_readint(inputstream)
- res=input_stream_readint(inputstream)
- res=input_stream_readbyte(inputstream)
- res=input_stream_readutf(inputstream)
- res=input_stream_readutf(inputstream)
- --puts(1,res&"\n")
- if object_id!=4294967295 then
- player_message_set(object_id_to_player_class[object_id],{res,33*12})
- end if
- res=input_stream_readutf(inputstream)
- -- this.name_ = badi.readUTF(); // UTF
- -- this.objectId_ = badi.readInt(); // Int
- -- this.numStars_ = badi.readInt(); // Int
- -- this.bubbleTime_ = badi.readUnsignedByte(); // UnsignedByte
- -- this.recipient_ = badi.readUTF(); // UTF
- -- this.text_ = badi.readUTF(); // UTF
- -- this.cleanText_ = badi.readUTF(); // UTF
- end procedure
- procedure ping_read()
- object res
- sequence write,temp
- res=input_stream_readint(inputstream)
- write=""
- write=writeint(write,res) --serial
- write=writeint(write,current_time()) --time
- --PONG = 16;
- temp=reverse(int_to_bytes(length(write)+5)) &16
- write=arcfour_encrypt_block2(write)
- send_buffer=append(send_buffer,{temp&write})
- end procedure
- procedure goto_packet_read()
- object res
- sequence write,temp
- res=input_stream_readint(inputstream)
- res=location_new_from_input(inputstream)
- location_delete(res)
- write=""
- write=writeint(write,current_time()) --time
- temp=reverse(int_to_bytes(length(write)+5)) &14
- write=arcfour_encrypt_block2(write)
- send_buffer=append(send_buffer,{temp&write})
- end procedure
- procedure shoot_packet_read()
- object res
- res=input_stream_readbyte(inputstream)
- res=input_stream_readint(inputstream)
- res=input_stream_readint(inputstream)
- res=location_new_from_input(inputstream)
- location_delete(res)
- res=input_stream_readint(inputstream)
- res=input_stream_readshort(inputstream)
- end procedure
- procedure play_sound_read()
- object res
- res=input_stream_readint(inputstream)
- res=input_stream_readbyte(inputstream)
- end procedure
- procedure traderequest_packet_read()
- object res
- sequence data,temp
- data={}
- res=input_stream_readutf(inputstream)
- puts(1,"trade requested "&res&"\n")
- --send_buffer=append(send_buffer,{useportal_packet_write(503)})
- --automaticly trade upon request
- --data=writeutf(data,res)
- --temp=reverse(int_to_bytes(length(data)+5)) &21
- --data=arcfour_encrypt_block2(data)
- --send_buffer=append(send_buffer,{temp&data})
- end procedure
- procedure tradestart_packet_read()
- object res
- integer size
- atom item,bt,eq,included
- size=input_stream_readshort(inputstream)
- for i=0 to size-1 do
- item=input_stream_readint(inputstream)
- bt=input_stream_readint(inputstream)
- eq=input_stream_readbool(inputstream)
- included=input_stream_readbool(inputstream)
- my_items=append(my_items,{item,bt,eq,included})
- end for
- puts(1,"my items\n")
- ?my_items
- res=input_stream_readutf(inputstream)
- size=input_stream_readshort(inputstream)
- for i=0 to size-1 do
- item=input_stream_readint(inputstream)
- bt=input_stream_readint(inputstream)
- eq=input_stream_readbool(inputstream)
- included=input_stream_readbool(inputstream)
- there_items=append(there_items,{item,bt,eq,included})
- end for
- puts(1,"there items\n")
- ?there_items
- end procedure
- procedure tradedone_packet_read()
- object res
- res=input_stream_readint(inputstream)
- res=input_stream_readutf(inputstream)
- puts(1,"tradedone "&res&"\n")
- end procedure
- procedure tradechanged_packet_read()
- integer size
- object res
- sequence items
- items={}
- size=input_stream_readshort(inputstream)
- for i=0 to size-1 do
- res=input_stream_readbool(inputstream)
- items&=res
- end for
- ?items
- end procedure
- procedure clientstat_packet_read()
- object res
- res=input_stream_readutf(inputstream)
- puts(1,res&"\n")
- res=input_stream_readint(inputstream)
- end procedure
- procedure reconnect_packet_read()
- object res
- integer size
- res=input_stream_readutf(inputstream)
- puts(1,"name "&res&"\n")
- res=input_stream_readutf(inputstream)
- puts(1,"host"&res&"\n")
- res=input_stream_readint(inputstream)
- puts(1,"port ")
- ?res
- puts(1,"\n")
- res=input_stream_readint(inputstream)
- puts(1,"game id")
- ?res
- puts(1,"\n")
- res=input_stream_readint(inputstream)
- puts(1,"key time")
- ?res
- size=input_stream_readshort(inputstream)
- ?size
- res=input_stream_readfully(inputstream,size)
- ?res
- --this.name_ = badi.readUTF(); // UTF
- --this.host_ = badi.readUTF(); // UTF
- -- this.port_ = badi.readInt(); // Int
- -- this.gameId_ = badi.readInt(); // Int
- -- this.keyTime_ = badi.readInt(); // Int
- -- short size = badi.readShort();
- -- this.key_ = new byte[size];
- -- badi.readFully(key_);
- end procedure
- procedure read_packet()
- integer packet_id,packet_len,temp
- sequence data
- object res
- --puts(1,"location class size "&sprint(location_classsize())&"\n")
- --puts(1,"object_status class size "&sprint(object_status_classsize())&"\n")
- --puts(1,"object_status_data class size "&sprint(object_status_data_classsize())&"\n")
- --puts(1,"stat_data class size "&sprint(stat_data_classsize())&"\n")
- --puts(1,"tile class size "&sprint(tile_classsize())&"\n")
- --puts(1,"size of player_class_list "&sprint(length(player_class_list))&"\n")
- while 1 do
- if input_stream_length(inputstream)>5 and input_stream_length(inputstream)>=bytes_to_int( {input_stream_peek(inputstream,4),input_stream_peek(inputstream,3),input_stream_peek(inputstream,2),input_stream_peek(inputstream,1)} ) then
- else
- for i=1 to length(send_buffer) do
- temp=WsockSendData(Server_sock,send_buffer[i][1])
- end for
- send_buffer={}
- exit
- end if
- packet_id=input_stream_peek(inputstream,5)
- packet_len=bytes_to_int( {input_stream_peek(inputstream,4),input_stream_peek(inputstream,3),input_stream_peek(inputstream,2),input_stream_peek(inputstream,1)} )
- --puts(1,"packet id\n")
- --?packet_id
- if input_stream_length(inputstream)>5 then
- data=arcfour_decrypt_block(input_stream_slice(inputstream,6,packet_len))
- input_stream_set(inputstream, input_stream_slice(inputstream,packet_len+1, input_stream_length(inputstream) ) )
- input_stream_set(inputstream, data&input_stream_get(inputstream))
- end if
- if packet_id=fail_packet then
- puts(1,"fail ")
- ?input_stream_readint(inputstream)
- puts(1,input_stream_readutf(inputstream)&"\n")
- elsif packet_id=ping_packet then
- ping_read()
- elsif packet_id=tradedone_packet then
- tradedone_packet_read()
- elsif packet_id=shoot_packet then
- shoot_packet_read()
- elsif packet_id=global_notification_packet then
- global_notification_read()
- elsif packet_id=play_sound_packet then
- play_sound_read()
- elsif packet_id=create_suc_packet then
- create_suc_packet_read()
- elsif packet_id=tradechanged_packet then
- tradechanged_packet_read()
- elsif packet_id=accountlist_packet then
- accountlist_read()
- elsif packet_id=goto_packet then
- goto_packet_read()
- elsif packet_id= show_effect_packet then
- show_effect_read()
- elsif packet_id= text_packet then
- text_read()
- elsif packet_id=reconnect_packet then
- reconnect_packet_read()
- elsif packet_id=update_packet then
- update_packet_read()
- elsif packet_id= new_tick_packet then
- new_tick_read()
- elsif packet_id=tradestart_packet then
- tradestart_packet_read()
- elsif packet_id= traderequest_packet then
- traderequest_packet_read()
- elsif packet_id= notification_packet then
- notification_read()
- elsif packet_id=mapinfo_packet then
- mapinfo_packet_read()
- elsif packet_id= allyshoot_packet then
- allyshoot_read()
- elsif packet_id=clientstat_packet then
- clientstat_packet_read()
- else
- ?packet_id
- puts(1,"unknow packet\n")
- sleep(100)
- end if
- end while
- end procedure
- procedure processServerMessage(atom hWnd, atom arg1, atom arg2)
- atom index, newsock
- integer action, sock, iwork
- object owork,junk
- sequence newIP,swork,rx,tx
- sequence data
- action = lo_word(arg2)
- sock = arg1
- if action=FD_CONNECT then
- puts(1,"connected\n")
- iwork=WsockSendData(sock,hello_packet_write())
- --iwork=WsockSendData(sock,create_packet_write())
- iwork=WsockSendData(sock,load_packet_write())
- elsif action = FD_READ then
- rx = ""
- owork = WsockReadData(sock,1)
- while sequence(owork) do
- rx = rx & owork
- owork = WsockReadData(sock,1)
- end while
- if length(rx) > 0 then
- input_stream_append(inputstream,rx)
- if input_stream_length(inputstream)>5 then
- --puts(1,"packet length "&sprint(bytes_to_int( {input_stream_peek(inputstream,4),input_stream_peek(inputstream,3),input_stream_peek(inputstream,2),input_stream_peek(inputstream,1)})) &" : actual len:"&sprint(input_stream_length(inputstream)) &"\n" )
- --puts(1,"packet id:"&sprint(input_stream_peek(inputstream,5))&"\n")
- if input_stream_length(inputstream)>=bytes_to_int( {input_stream_peek(inputstream,4),input_stream_peek(inputstream,3),input_stream_peek(inputstream,2),input_stream_peek(inputstream,1)} ) then
- read_packet()
- end if
- end if
- end if
- elsif action = FD_CLOSE then
- puts(1,"server closed\n")
- WsockCloseSocket(sock)
- --setTimer(Window1,1002,1000*60)
- end if
- end procedure
- --old code obslete keeped for reseaons unknow
- procedure main_loop()
- integer temp
- atom t_start,t_end
- while running=1 do
- for i=1 to 1000 do
- doEvents(0)
- end for
- t_start=get_tick_count()
- if input_stream_length(inputstream)>5 then
- if input_stream_length(inputstream)>=bytes_to_int( {input_stream_peek(inputstream,4),input_stream_peek(inputstream,3),input_stream_peek(inputstream,2),input_stream_peek(inputstream,1)} ) then
- --puts(1,"packet length "&sprint(bytes_to_int( {input_stream_peek(inputstream,4),input_stream_peek(inputstream,3),input_stream_peek(inputstream,2),input_stream_peek(inputstream,1)})) &" : actual len:"&sprint(input_stream_length(inputstream)) &"\n" )
- --puts(1,"packet id:"&sprint(input_stream_peek(inputstream,5))&"\n")
- read_packet()
- end if
- end if
- for i=1 to length(send_buffer) do
- --?send_buffer[i][1]
- --puts(1,"\n")
- temp=WsockSendData(Server_sock,send_buffer[i][1])
- end for
- send_buffer={}
- t_end=get_tick_count()
- if 100-(t_end-t_start)>=1 then
- --usleep(100-(t_end-t_start))
- end if
- --puts(1,"time "&sprint(t_end-t_start)&"\n")
- end while
- abort(0)
- end procedure
- setTimer(Window1,1001,1000)
- setTimer(Window1,1010,30)
- --==============================CWindow1 events==============================--
- procedure draw_text_bubble(integer x, integer y,sequence text)
- sequence messages
- integer pixelw,pos1,upy
- messages={}
- pos1=1
- pixelw=0
- for i=1 to length(text) do
- pixelw+=text_sizes[ text[i] ]
- if pixelw>=200 then
- messages=append(messages,text[pos1..i])
- pos1=i+1
- pixelw=0
- end if
- end for
- if length(messages) then
- if pixelw>0 then
- messages=append(messages,text[pos1..length(text)])
- end if
- upy=floor(pixelh*length(messages))
- allegro:rectfill(buffer,x,y-upy,x+200,y,makecol(0,0,192))
- allegro:rect(buffer,x,y-upy,x+200,y,makecol(0,192,0))
- for i=1 to length(messages) do
- allegro:textout_ex(buffer,font, messages[i], x, (y+(pixelh*i)-pixelh)-upy , makecol(0,0,0), -1 )
- end for
- else
- upy=floor(pixelh*1)
- allegro:rectfill(buffer,x,y-upy,x+pixelw,y,makecol(0,0,192))
- allegro:rect(buffer,x,y-upy,x+pixelw,y,makecol(0,192,0))
- allegro:textout_ex(buffer,font, text, x, (y+(pixelh*1)-pixelh)-upy , makecol(0,0,0), -1 )
- end if
- end procedure
- procedure cwindow1_paint()
- atom hdc
- atom x,y
- sequence float
- integer mapx,mapy
- hdc=getDC(CWindow1)
- clear_to_color(buffer,color_background)
- --allegro:line(buffer,-view_left,-view_top,workspace_width-view_left,workspace_height-view_top,color_black)
- allegro:rect(buffer,0-view_left,0-view_top,800-view_left,600-view_top,color_red)
- --allegro:textout_ex(buffer,font, sprint(view_top)&" "&sprint(window_height)&" "&sprint(view_top+window_height) ,100-view_left , 100-view_top , makecol(255,0,0),-1 )
- --allegro:textout_ex(buffer,font, sprint(view_left)&" "&sprint(view_top), 0 , 0 , makecol(255,0,0),-1 )
- --allegro:textout_ex(buffer,font, sprint(view_top)&" "&sprint(window_height)&" "&sprint(view_top+window_height) ,100 , 100 , makecol(255,0,0),-1 )
- if key_check(VK_LEFT)=1 then
- my_position[1]-=0.10
- my_position_real[1]-=0.10
- elsif key_check(VK_RIGHT)=1 then
- my_position[1]+=0.10
- my_position_real[1]+=0.10
- end if
- if key_check(VK_UP)=1 then
- my_position[2]-=0.10
- my_position_real[2]-=0.10
- elsif key_check(VK_DOWN)=1 then
- my_position[2]+=0.10
- my_position_real[2]+=0.10
- end if
- if length(my_position)!=0 then
- --view_left=convert3dspaceto2d(my_position[1])-400
- --view_top=convert3dspaceto2d(my_position[2])-300
- view_left=convert3dspaceto2d(my_position_real[1])-400
- view_top=convert3dspaceto2d(my_position_real[2])-300
- end if
- mapx=floor(view_left/space3dto2d)
- mapy=floor(view_top/space3dto2d)
- --800/32 ==25
- --600/32 ==18.75
- if length(map_data) then
- --puts(1,"view_left "&sprint(view_left)&"\n")
- --puts(1,"view_top "&sprint(view_top)&"\n")
- for yy=mapy to mapy+19 do
- for xx=mapx to mapx+25 do
- if xx>0 and yy>0 then
- if map_data[yy][xx]=122 then
- --puts(1,"found\n")
- draw_sprite(buffer,tile_bitmaps[1], (xx*space3dto2d)-view_left,(yy*space3dto2d)-view_top)
- elsif map_data[yy][xx]=58 then
- draw_sprite(buffer,tile_bitmaps[2], (xx*space3dto2d)-view_left,(yy*space3dto2d)-view_top)
- elsif map_data[yy][xx]=121 then
- draw_sprite(buffer,tile_bitmaps[3], (xx*space3dto2d)-view_left,(yy*space3dto2d)-view_top)
- end if
- end if
- end for
- end for
- end if
- for i=1 to length(player_class_list) do
- if length(player_class_list[i]) then
- if player_class_list[i][1]!=my_object_id then
- draw_sprite(buffer,player_bitmaps[ player_bitmap_offset[ player_class_list[i][4] ] ], player_class_list[i][5][1]-view_left,player_class_list[i][5][2]-view_top)
- allegro:textout_ex(buffer,font, player_class_list[i][6] ,(player_class_list[i][5][1]-view_left)-8,(player_class_list[i][5][2]-view_top)+32 , makecol(0,0,0),-1 )
- else
- draw_sprite(buffer,player_bitmaps[ player_bitmap_offset[ player_class_list[i][4] ] ], convert3dspaceto2d(my_position_real[1])-view_left,convert3dspaceto2d(my_position_real[2])-view_top)
- allegro:textout_ex(buffer,font, player_class_list[i][6] ,(convert3dspaceto2d(my_position_real[1])-view_left)-8,(convert3dspaceto2d(my_position_real[2]) -view_top )+32 , makecol(0,0,0),-1 )
- end if
- end if
- end for
- for i=1 to length(player_class_list) do
- if length(player_class_list[i]) then
- if player_class_list[i][7][2]>0 then
- player_class_list[i][7][2]-=1
- --allegro:rectfill(buffer,player_class_list[i][5][1]-view_left,(player_class_list[i][5][2]-40)-view_top,(player_class_list[i][5][1]+80)-view_left,(player_class_list[i][5][2])-view_top,color_blue)
- draw_text_bubble( player_class_list[i][5][1]-view_left,player_class_list[i][5][2]-view_top , player_class_list[i][7][1])
- --allegro:textout_ex(buffer,font, player_class_list[i][7][1] ,player_class_list[i][5][1]-view_left,(player_class_list[i][5][2]-40)-view_top , makecol(0,0,0),color_white )
- end if
- end if
- end for
- blit_to_hdc(buffer,hdc,0,0,0,0,window_width,window_height)
- releaseDC(hdc)
- end procedure
- procedure cwindow1_resize()
- sequence size
- size=getCtlSize( Window1 )
- --view width\height
- window_width=size[1]
- window_height=size[2]-(window_titlebar_height+20)
- destroy_bitmap(buffer)
- buffer=0--might catch a bug
- if window_width>workspace_width then
- window_width=workspace_width
- end if
- if window_height>workspace_height then
- window_height=workspace_height
- end if
- if window_width<1 then
- window_width=1
- end if
- if window_height<1 then
- window_height=1
- end if
- buffer=create_bitmap(window_width,window_height)
- end procedure
- --------------------------------------------------------------------------------
- procedure Window1_onClose (integer self, integer event, sequence params)--params is ()
- running=0
- WsockCloseSocket(Server_sock)
- close_allegro()
- --returnValue(-1)
- end procedure
- setHandler( Window1, w32HClose, routine_id("Window1_onClose"))
- --------------------------------------------------------------------------------
- procedure Window1_onEvent (integer self, integer event, sequence params)--params is ( int iMsg, atom wParm, atom lParm )
- if params[1] = SM_ASYNC then
- processServerMessage(hWndMainWindow,params[2],params[3])
- end if
- end procedure
- setHandler( Window1, w32HEvent, routine_id("Window1_onEvent"))
- --------------------------------------------------------------------------------
- procedure Window1_onKeyDown (integer self, integer event, sequence params)--params is ( atom scanCode, atom shift )
- key_add(params[1])
- end procedure
- setHandler( Window1, w32HKeyDown, routine_id("Window1_onKeyDown"))
- --------------------------------------------------------------------------------
- procedure Window1_onKeyUp (integer self, integer event, sequence params)--params is ( int scanCode, int shift )
- key_remove(params[1])
- end procedure
- setHandler( Window1, w32HKeyUp, routine_id("Window1_onKeyUp"))
- --------------------------------------------------------------------------------
- procedure Window1_onOpen (integer self, integer event, sequence params)--params is ()
- integer iwork, port
- sequence swork,ip
- port = 2050
- iwork = WsockInit()
- if iwork = -1 then -- WinSock failed
- iwork = message_box("WSockInit() failed!","Error",MB_TASKMODAL + MB_ICONSTOP + MB_OK)
- abort(99)
- end if
- hWndMainWindow = getHandle(Window1)
- --blocking connect, might need to make this none blocking
- --Server_sock=Wsock_new("ec2-176-34-195-206.eu-west-1.compute.amazonaws.com", 2050 , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
- Server_sock=Wsock_new("50.18.113.133", 2050 , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
- --Server_sock=Wsock_new("127.0.0.1", 2050 , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
- --Server_sock=WsockSocket(AF_INET,SOCK_STREAM)
- --if WSAAsyncSelect(Server_sock,hWndMainWindow,SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))!=0 then
- -- puts(1,"WSAAsyncSelect error\n")
- --end if
- --ip=WsockHostInfo("ec2-176-34-195-206.eu-west-1.compute.amazonaws.com")
- --puts(1,ip[2])
- --?WsockConnectAsync(Server_sock,2050,ip[2])
- --Server = WsockListenAsync(port, hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_ACCEPT,FD_CLOSE,FD_WRITE}))
- --if Server_sock = SOCKET_ERROR then -- WinSock failed
- -- iwork = message_box("WsockListenAsync() failed!","Error",MB_TASKMODAL+MB_ICONSTOP+MB_OK)
- -- abort(99)
- --end if
- startup_allegro()
- end procedure
- setHandler( Window1, w32HOpen, routine_id("Window1_onOpen"))
- --------------------------------------------------------------------------------
- procedure Window1_onResize (integer self, integer event, sequence params)--params is ( int style, int cx, int cy )
- sequence size
- size=getCtlSize(Window1)
- setCtlSize(CWindow1,size[1],size[2]-(window_titlebar_height))
- end procedure
- setHandler( Window1, w32HResize, routine_id("Window1_onResize"))
- --------------------------------------------------------------------------------
- procedure Window1_onTimer (integer self, integer event, sequence params)--params is ( int timerId)
- if params[1]=1001 then
- killTimer(Window1,1001)
- --main_loop()
- elsif params[1]=1002 then
- Server_sock=Wsock_new("ec2-176-34-195-206.eu-west-1.compute.amazonaws.com", 2050 , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
- elsif params[1]=1010 then
- setTimer(CWindow1,1001,10)
- end if
- end procedure
- setHandler( Window1, w32HTimer, routine_id("Window1_onTimer"))
- --------------------------------------------------------------------------------
- procedure CWindow1_onOpen (integer self, integer event, sequence params)--params is ()
- setTimer(CWindow1,1001,100)
- end procedure
- setHandler( CWindow1, w32HOpen, routine_id("CWindow1_onOpen"))
- --------------------------------------------------------------------------------
- procedure CWindow1_onPaint (integer self, integer event, sequence params)--params is ( int x1, int y1, int x2, int y2 )
- setTimer(CWindow1,1001,0)
- end procedure
- setHandler( CWindow1, w32HPaint, routine_id("CWindow1_onPaint"))
- --------------------------------------------------------------------------------
- procedure CWindow1_onResize (integer self, integer event, sequence params)--params is ( int style, int cx, int cy )
- cwindow1_resize()
- end procedure
- setHandler( CWindow1, w32HResize, routine_id("CWindow1_onResize"))
- --------------------------------------------------------------------------------
- procedure CWindow1_onTimer (integer self, integer event, sequence params)--params is ( int timerId)
- if params[1]=1001 then
- cwindow1_paint()
- killTimer(CWindow1,1001)
- end if
- end procedure
- setHandler( CWindow1, w32HTimer, routine_id("CWindow1_onTimer"))
- WinMain( Window1,Normal )
- --this program has 1438 lines without including this line. If there is a discrepancy please send this file zipped to Judith.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement