Advertisement
Guest User

Untitled

a guest
May 6th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 42.00 KB | None | 0 0
  1. --  code generated by Win32Lib IDE v0.21.1 Build Sept-29-2006
  2.  
  3. constant TheProgramType="exw"
  4.  
  5. include Win32Lib.ew
  6. without warning
  7.  
  8. --------------------------------------------------------------------------------
  9. --  Window Window1
  10. constant Window1 = createEx( Window, "rotmg client 13.2", 0, Default, Default, 800, 600, 0, 0 )
  11. sequence IDEFlags
  12. IDEFlags = classDefaults( Window, { {1, {WS_SYSMENU}},{2, {0}} } )
  13. constant CWindow1 = createEx( Window, "", Window1, 0, 0, 320, 180, w32or_all({WS_CHILD, WS_CLIPSIBLINGS}), 0 )
  14. openWindow(CWindow1, Normal)
  15. moveZOrder( CWindow1, HWND_TOP)
  16. ---------------------------------------------------------
  17. --------------------------------------------------------------------------------
  18. include SrvSckIP.ew
  19. include ARCFOUR.EW
  20. include ARCFOUR2.EW
  21. include euallegro.ew as allegro
  22.  
  23. constant space3dto2d=32
  24.  
  25. function real(sequence string)
  26. sequence temp
  27. temp=value(string)
  28. return temp[2]
  29. end function
  30.  
  31. procedure centerwindow(integer win)
  32. integer width,height,window_width,window_height
  33. sequence size
  34.     size=getCtlSize(win)
  35.     window_width=size[1]
  36.     window_height=size[2]
  37.     width=w32Func(xGetSystemMetrics,{SM_CXSCREEN})
  38.     height=w32Func(xGetSystemMetrics,{SM_CYSCREEN})
  39.     setRect( win,floor((width/2))-floor((window_width/2)) ,floor((height/2))-floor((window_height/2))-32, window_width, window_height, 0 )
  40. end procedure
  41.  
  42. function rgb2( integer r, integer g, integer b )
  43.     return makecol(r,g,b)
  44. end function
  45.  
  46. sequence key_buffer
  47. key_buffer={}
  48.  
  49. function remove_line(sequence string, integer line)
  50. sequence temp
  51. integer len
  52.   len=length(string)
  53.   if line=1 then
  54.     return string[2..len]
  55.   elsif line=len then
  56.     return string[1..len-1]
  57.   else
  58.     temp=string[1..line-1]
  59.     return temp&string[line+1..len]
  60.   end if
  61. end function
  62.  
  63. procedure key_add(integer scancode)
  64. integer found
  65. found=0
  66.   for i=1 to length(key_buffer) do
  67.     if key_buffer[i]=scancode then
  68.       found=1
  69.       exit
  70.     end if
  71.   end for
  72.   if found=0 then
  73.     key_buffer=append(key_buffer,scancode)
  74.   end if
  75. end procedure
  76.  
  77. procedure key_remove(integer scancode)
  78.   for i=1 to length(key_buffer) do
  79.      if key_buffer[i]=scancode then
  80.        key_buffer=remove_line(key_buffer,i)
  81.        exit
  82.      end if
  83.   end for
  84. end procedure
  85.  
  86. function key_check(integer scancode)
  87.    for i=1 to length(key_buffer) do
  88.      if key_buffer[i]=scancode then
  89.        return 1
  90.      end if
  91.   end for
  92.   return 0
  93. end function
  94.  
  95. constant window_titlebar_height = getSystemMetrics ( SM_CYCAPTION )
  96. constant window_menu_height = getSystemMetrics ( SM_CYMENU )
  97. constant window_hscrollbar_width = getSystemMetrics ( SM_CXVSCROLL )
  98. constant window_vscrollbar_height = getSystemMetrics ( SM_CYVSCROLL )
  99. constant window_border_width = getSystemMetrics ( SM_CXFRAME )
  100. constant window_border_height = getSystemMetrics ( SM_CYFRAME )
  101. constant window_toolbar_height = 33
  102.  
  103. constant window_all_height=window_titlebar_height+window_menu_height+window_toolbar_height+(getSystemMetrics ( SM_CYFRAME )*2)
  104.  
  105. function convert3dspaceto2d(atom v)
  106.   sequence float
  107.   integer haspoint,leftside,padleft,padright
  108.   atom rightside
  109.   haspoint=0
  110.  
  111.   float=sprint(v)
  112.   for i=1 to length(float) do
  113.     if float[i]='.' then
  114.       haspoint=1
  115.       leftside=real(float[1..i-1])
  116.       rightside=real("0."&float[i+1..length(float)])
  117.     end if
  118.   end for
  119.  
  120.   if haspoint=1 then
  121.     padleft=floor(space3dto2d*leftside)
  122.     padright=floor(space3dto2d*rightside)
  123.     return padleft+padright
  124.   else
  125.     return space3dto2d*v
  126.   end if
  127. end function
  128.  
  129.  
  130. --================================setup allegro============================--
  131. atom temp_bitmap
  132. sequence player_bitmaps,tile_bitmaps
  133. atom the_palette
  134. atom buffer
  135. object ret
  136. integer window_width,window_height,workspace_width,workspace_height
  137. integer view_left,view_top
  138. atom color_white,color_black,color_pink,color_green,color_blue,color_red,color_background
  139.  
  140. buffer=0
  141. window_width=800
  142. window_height=600
  143. workspace_width=4000
  144. workspace_height=4000
  145. view_left=0
  146. view_top=0
  147.  
  148. player_bitmaps={}
  149. tile_bitmaps={}
  150.  
  151. sequence text_sizes
  152. integer pixelh
  153.  
  154. procedure startup_allegro()
  155.  
  156. integer ret
  157. win_set_window(getHWND(Window1))
  158. the_palette = allocate_palette()
  159. if allegro_init()!= 0 then
  160.   puts(1,"init\n")
  161. end if
  162. if install_timer()!= 0 then
  163.   puts(1,"timer\n")
  164. end if
  165. ret=reserve_voices (1, -1)
  166. if install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, "")!= 0 then
  167.   puts(1,"install sound\n")
  168. end if
  169. set_color_depth(16)
  170. set_palette(the_palette)
  171.  
  172. color_white=rgb2(255,255,255)
  173. color_black=rgb2(0,0,0)
  174. color_pink=rgb2(255,0,255)
  175. color_green=rgb2(0,255,0)
  176. color_blue=rgb2(0,0,255)
  177. color_red=rgb2(255,0,0)
  178.  
  179. color_background=color_white--rgb2(239,235,214)
  180.  
  181. temp_bitmap=load_bitmap("images\\players.bmp", the_palette)
  182.  
  183. for i=1 to 294 do
  184.   player_bitmaps&=create_bitmap(space3dto2d,space3dto2d)
  185.   blit(temp_bitmap,player_bitmaps[length(player_bitmaps)],(space3dto2d*i)-space3dto2d,0,0,0,space3dto2d,space3dto2d)
  186. end for
  187.  
  188. tile_bitmaps&=load_bitmap("images\\tile1.bmp", the_palette)
  189. tile_bitmaps&=load_bitmap("images\\tile2.bmp", the_palette)
  190. tile_bitmaps&=load_bitmap("images\\tile3.bmp", the_palette)
  191.  
  192.  
  193. buffer=create_bitmap(window_width,window_height)
  194. clear_to_color(buffer,color_background)
  195.  
  196.  
  197.  
  198. text_sizes=repeat(0,1024)
  199. for i=32 to 127 do
  200.   text_sizes[i]=text_length(font,sprint(i))/2
  201.  
  202. end for
  203.  
  204. puts(1,"test "&sprint(text_sizes[32])&"\n")
  205. pixelh=text_height(font)
  206.  
  207. end procedure
  208.  
  209. procedure close_allegro()
  210.   destroy_palette(the_palette)
  211.   destroy_bitmap(buffer)
  212.  
  213.   for i=1 to length(player_bitmaps) do
  214.     destroy_bitmap(player_bitmaps[i])
  215.   end for
  216.  
  217.   allegro_exit()
  218. end procedure
  219.  
  220. --load_midi
  221. --play_midi(the_music, 1)
  222. --play_sample(the_sample, 255, pan, pitch, 1)
  223. --destroy_midi(the_music)
  224. --buffer=create_bitmap(view_width,view_height)
  225. --destroy_bitmap(buffer)
  226. --load_sample("buzzer.wav")
  227. --destroy_sample(buzzer_sfx)
  228. --load_bitmap("marty.bmp", the_palette)
  229.  
  230. --================================end setup allegro==========================--
  231.  
  232. sequence map_data
  233. integer map_width,map_height
  234. map_width=255
  235. map_height=255
  236. map_data={}
  237.  
  238.  
  239. --new main loop control
  240. integer running
  241. running=1
  242. atom start_time
  243. start_time=0
  244. integer current_tick
  245. current_tick=0
  246.  
  247. integer my_object_id
  248. my_object_id=0
  249.  
  250. sequence my_position
  251. my_position={}
  252. sequence my_position_real
  253. my_position_real={}
  254. sequence my_status
  255. my_status={}
  256. --end main loop control
  257.  
  258. sequence my_items,there_items
  259. my_items={}
  260. there_items={}
  261.  
  262. sequence object_id_to_player_class
  263. object_id_to_player_class=repeat(0,2000000) --2 million objects
  264.  
  265. constant player_constants={806,805,804,803,802,801,800,799,798,797,784,782,775,768}
  266. sequence player_bitmap_offset
  267. integer tmp
  268. player_bitmap_offset=repeat(0,length(player_constants))
  269. tmp=length(player_constants)
  270.  
  271. for i=1 to length(player_constants) do
  272.   player_bitmap_offset[tmp]=(21*(i-1))+8
  273.   tmp-=1
  274. end for
  275.  
  276. include input_stream.ew
  277. include output_stream.ew
  278. include location.ew
  279. include object_status.ew
  280. include object_status_data.ew
  281. include stat_data.ew
  282. include tile.ew
  283.  
  284. include players.ew
  285.  
  286. constant inputstream = input_stream_new()
  287. constant outputstream = output_stream_new()
  288.  
  289. constant xGetTickCount = registerw32Function(kernel32, "GetTickCount", {}, C_LONG)
  290. constant xSleep = registerw32Procedure(kernel32, "Sleep", {C_LONG})
  291.  
  292. procedure usleep(integer v)
  293.     w32Proc(xSleep,{v})
  294. end procedure
  295.  
  296. function get_tick_count()
  297.   return  w32Func(xGetTickCount,{})
  298. end function
  299.  
  300. --public int currentTime() {
  301. --      return (int) (System.currentTimeMillis() - startTime);
  302. --  }
  303.  
  304. function current_time()
  305.   return  w32Func(xGetTickCount,{})-start_time
  306. end function
  307.  
  308. sequence send_buffer
  309. send_buffer={}
  310.  
  311. global constant SM_ASYNC = #FFFF
  312. atom hWndMainWindow
  313. atom Server_sock
  314.  
  315. constant double_max_value=1.7976931348623157E308
  316.  
  317. function create_guest_guid_old()
  318.   atom uid
  319.   uid=  0.6176749197488145--+rand(1073741823)
  320.   return uid*double_max_value  
  321. end function
  322.  
  323. function create_guest_guid_java()
  324.   integer fn,char
  325.   sequence data
  326.   fn=open("input.txt","w")
  327.   start_time=get_tick_count()
  328.   puts(fn,sprint(start_time))
  329.   close(fn)
  330.   if system_exec("guest.bat", 2) then
  331.     puts(2, "failure!\n")
  332.   end if
  333.   fn=open("output.txt","rb")
  334.   data=gets(fn)
  335.   close(fn)
  336.   return data
  337. end function
  338.  
  339. function create_login_guid_java(sequence email,sequence pass)
  340.   integer fn,char
  341.   sequence data
  342.   fn=open("input.txt","w")
  343.   puts(fn,email&":"&pass)
  344.   close(fn)
  345.   if system_exec("login.bat", 2) then
  346.     puts(2, "failure!\n")
  347.   end if
  348.   fn=open("output.txt","rb")
  349.   data=gets(fn)
  350.   close(fn)
  351.   for i=1 to length(data) do
  352.     if data[i]=' ' then
  353.       data={data[1..i-1],data[i+1..length(data)]}
  354.       exit 
  355.     end if
  356.   end for
  357.   return data
  358. end function
  359.  
  360. procedure debug(sequence text)
  361.   puts(1,text&"\n")
  362. end procedure
  363.  
  364. sequence key1,key2
  365.  
  366. --these work
  367. --key1 is for encrypting data to send to the client
  368. key1={114,197,88,60,175,182,129,137,149,203,215,75,128}
  369. --key2 is for decrypting data from the client
  370. key2={49,31,128,105,20,81,199,27,9,161,58,42,110}
  371. --finaly got rc4 encrption working 27/03/2013 --update streaming cipher working 03/05/2013
  372.  
  373. arcfour_init_encrypt(key1)
  374. arcfour_init_encrypt2(key2)
  375.  
  376. -----------------------------write functions--------------------------------------
  377.  
  378. function writeutf(sequence data, sequence v)
  379.   sequence s
  380.    s=int_to_bytes(length(v))
  381.    data&=s[2]&s[1]&v
  382.    return data
  383. end function
  384.  
  385. function writeint(sequence data ,atom v)
  386. sequence s
  387.    s=int_to_bytes(v)
  388.    data&=s[4]&s[3]&s[2]&s[1]
  389.    return data
  390. end function
  391.  
  392. function writefloat(sequence data ,atom v)
  393. sequence s
  394.    s = atom_to_float32(v)
  395.    data&=s[4]&s[3]&s[2]&s[1]
  396.    return data
  397. end function
  398.  
  399. function writebool(sequence data, integer b)
  400.    data&=b
  401.    return data
  402. end function
  403.  
  404. function writeshort(sequence data ,atom v)
  405. sequence s
  406.    s=int_to_bytes(v)
  407.    data&=s[2]&s[1]
  408.    return data
  409. end function
  410.  
  411. function writebyte(sequence data ,integer v)
  412.    data&=v
  413.    return data
  414. end function
  415.  
  416. constant fail_packet=0
  417. constant useportal_packet=3--USEPORTAL = 3;
  418. constant ping_packet=6
  419. constant global_notification_packet=9
  420. constant tradedone_packet=12--TRADEDONE:int = 12;
  421. constant shoot_packet=13
  422. constant hello_packet=17
  423. constant requesttrade_packet=21--REQUESTTRADE = 21;
  424. constant tradechanged_packet=23--TRADECHANGED = 23;
  425. constant text_packet=25 --TEXT
  426. constant update_packet=26
  427. constant create_suc_packet=31
  428. constant create_packet=36
  429. constant reconnect_packet=39--RECONNECT = 39;
  430. constant play_sound_packet=44
  431. constant load_packet=45
  432. constant accountlist_packet=46
  433. constant goto_packet=52
  434. constant show_effect_packet=56
  435. constant mapinfo_packet=60
  436. constant traderequest_packet=61 --TRADEREQUESTED = 61;
  437. constant new_tick_packet=62-- NEW_TICK = 62
  438. constant notification_packet=63 --NOTIFICATION
  439. constant tradestart_packet=67--TRADESTART = 67;
  440. constant allyshoot_packet=74 --ALLYSHOOT
  441. constant clientstat_packet=75--CLIENTSTAT = 75;
  442.  
  443.  
  444. function hello_packet_write()
  445.   sequence data,temp
  446.   data={}
  447.   data=writeutf(data,"13.2") --build version
  448.   data=writeint(data,-2) --game id
  449.   --data=writeutf(data,"XRU8xQGLzCLaQR2BMOVLE9aPLggIPbNcig/rA1Wyi+KnlfIO02VXKpDEMO7hjscFXccRGOnTHpKoLkbuo2OXrU0wGWzJLsNGSf007Ga71Eu6VCZ61dNIzm71qKl9B5z7ERceI/JFk9NQ7RvmdQpK1s+bB9qAsVWGwhlECBA4EU0=")--create_guest_guid_java())--"PAP6RSeDHDRLpNVO4dw7oMsZS/6gIdnSFj9LHjI/YL8Al61XUPAxMtx5d/fYzmdwbgdRed6X1pHcVKUX16q59wvlzVouQZeim0P8HwXxbuMWwS+Bf9YFUANoriQzjMV/PlNAc17GfxkVQAn2LNYSV3m+BfEAwE6/WUNtyIYZJWI=") --guid
  450.   --data=writeutf(data,"Z+TWxbDpdKsNAKn358XZHOTI4nZEI4/oCrOB7CI8uDYdgWmXN4DKwfCcONgurW+xrGEWoLzviOyg5yRYxaeV55N7OB75OSGtslcs4Tjc8oNRILQG5wofw2YH+MG/jWshUfxC8yQBWJ/Akn+j1ROuS4+CEgjklZjLGC/Oc0EVgDQ=")
  451.  
  452.    --login deatils
  453.   temp=create_login_guid_java("gdasgdshgdsh@gmail.com","123456")
  454.   data=writeutf(data,temp[1])
  455.   data=writeutf(data,temp[2])
  456.   --puts(1,temp[1]&"\n")
  457.   --puts(1,temp[2]&"\n")
  458.  
  459.   --guest accoun login
  460.   --data=writeutf(data,create_guest_guid_java())
  461.   --data=writeutf(data,"") --pass
  462.  
  463.   data=writeutf(data,"") --secert
  464.   data=writeint(data,-1) --key time
  465.   data=writeshort(data,0)
  466.   --data=writebyte(data,0) --
  467.   data=writeint(data,0)  --jd length
  468.   --data=writebyte(data,0) -- jd bytes
  469.  
  470.   data=writeutf(data,"") --pk
  471.   data=writeutf(data,"rotmg") --tq
  472.   data=writeutf(data,"") --h
  473.   data=writeutf(data,"rotmg") --platforum
  474.  
  475.   data=writeutf(data,"") --unknow
  476.  
  477.   temp=reverse(int_to_bytes(length(data)+5)) &hello_packet
  478.  
  479.   data=arcfour_encrypt_block2(data)
  480.   return temp & data
  481. end function
  482.  
  483. --integer map_width,map_height
  484. sequence map_name
  485.  
  486. procedure mapinfo_packet_read()
  487.   object temp
  488.   sequence data
  489.     map_width=input_stream_readint(inputstream)
  490.     map_height=input_stream_readint(inputstream)
  491.     map_name=input_stream_readutf(inputstream)
  492.     temp=input_stream_readint(inputstream)
  493.     temp=input_stream_readint(inputstream)
  494.     temp=input_stream_readbool(inputstream)
  495.     temp=input_stream_readbool(inputstream)
  496.  
  497.     puts(1,input_stream_get(inputstream)&"\n")
  498.     input_stream_set(inputstream, "")
  499.    
  500.     map_data={}
  501.     for i=1 to map_height do
  502.       map_data=append(map_data,repeat(0,map_width))
  503.     end for
  504. --init to zero
  505.    
  506. end procedure
  507.  
  508. function create_packet_write()
  509.   sequence data,temp
  510.   data={}
  511.  
  512.   data=writeshort(data,782)
  513.   data=writeshort(data,0)
  514.  
  515.   temp=reverse(int_to_bytes(length(data)+5)) &create_packet
  516.  
  517.   data=arcfour_encrypt_block2(data)
  518.  
  519.   return temp & data
  520. end function
  521.  
  522. function load_packet_write()
  523.   sequence data,temp
  524.   data={}
  525.  
  526.   data=writeint(data,4)
  527.  
  528.   temp=reverse(int_to_bytes(length(data)+5)) &45
  529.  
  530.   data=arcfour_encrypt_block2(data)
  531.   return temp & data
  532. end function
  533.  
  534. function useportal_packet_write(integer num)
  535.   sequence data,temp
  536.   data={}
  537.  
  538.   data=writeint(data,num)
  539.  
  540.   temp=reverse(int_to_bytes(length(data)+5)) &useportal_packet
  541.  
  542.   data=arcfour_encrypt_block2(data)
  543.   return temp & data
  544. end function
  545.  
  546.  
  547. procedure create_suc_packet_read()
  548.   object res
  549.   puts(1,"create_suc\n")
  550.   my_object_id=input_stream_readint(inputstream)
  551.   ?my_object_id
  552.   --?res
  553.   res=input_stream_readint(inputstream)
  554.   ?res
  555.   --?res
  556. end procedure
  557.  
  558. procedure update_packet_read()
  559.   object res
  560.   integer size,object_type,index
  561.   integer found
  562.   sequence temp,temp2,stats
  563.  
  564.   --new code optimizeation
  565.   integer object_id
  566.   sequence position
  567.   integer class
  568.  
  569.   --
  570.   integer fn
  571.  
  572.   --puts(1,"updated\n")
  573.   size=input_stream_readshort(inputstream)
  574.  
  575.   --puts(1,"tile size "&sprint(size)&"\n")
  576.   if size!=0 then --tiles
  577.     --fn=open("tiles.txt","w")
  578.     for i=0 to size-1 do
  579.       res=tile_new_from_input(inputstream)
  580.       res=tile_get(res)
  581.       map_data[res[2]][res[1]]=res[3]
  582.       --puts(fn,sprint(tile_get_type(res))&"\n")
  583.    
  584.     end for
  585.     --for yy=1 to 255 do
  586.       --for xx=1 to 255 do
  587.         --puts(fn,sprint(map_data[yy])&"\n")
  588.       --end for
  589.     --end for
  590.     --close(fn)
  591.  
  592.   end if
  593.  
  594.   size=input_stream_readshort(inputstream)
  595.   --puts(1,"newobj size "&sprint(size)&"\n")
  596.   if size!=0 then --new obj
  597.     for i=0 to size-1 do
  598.       res=object_status_new_from_input(inputstream)
  599.       temp=object_status_get(res)
  600.       --?temp[1]--object type
  601.       found=0
  602.       for j=1 to length(player_constants) do
  603.         if temp[1]=player_constants[j] then
  604.           found=j
  605.         end if
  606.       end for
  607.       if found!=0 then
  608.        
  609.    
  610.    
  611.       --my object code--
  612.       temp=object_status_data_get(temp[2])
  613.       --puts(1,sprint(temp[1])&"\n")
  614.       if temp[1]=my_object_id then
  615.         puts(1,"my status updated\n")
  616.         my_position=location_get(temp[2])
  617.         my_position_real=my_position
  618.         for j=1 to length(temp[3]) do
  619.           temp2=stat_data_get(temp[3][j])
  620.           --?temp2
  621.           --if temp2[1]=31 then
  622.           --    puts(1,temp2[3]&"\n")
  623.           --    ?j
  624.           --end if
  625.           my_status=append(my_status,temp2)
  626.         end for
  627.         --?length(my_status)
  628.         --?my_status
  629.         --?location_get(temp[2])
  630.       end if
  631.       -- end my object code
  632.    
  633.       stats={}
  634.       temp=object_status_data_get(temp[2])
  635.       for j=1 to length(temp[3]) do
  636.         temp2=stat_data_get(temp[3][j])        
  637.         stats=append(stats,temp2)
  638.       end for
  639.    
  640.       --player_list=append(player_list,{temp[1],stats,location_get(temp[2]),found})
  641.       position=location_get(temp[2])
  642.       object_id_to_player_class[temp[1]]=player_new(temp[1],stats,position,found,{convert3dspaceto2d(position[1]),convert3dspaceto2d(position[2])},stats[29][3])
  643.  
  644.       object_status_delete(res)
  645.    
  646.       end if
  647.  
  648.     end for
  649.   end if
  650.  
  651.   size=input_stream_readshort(inputstream)
  652.   --puts(1,"drop size "&sprint(size)&"\n")
  653.  
  654.   for i=0 to size-1 do
  655.      res=input_stream_readint(inputstream)
  656.    
  657.      --new optimize code
  658.      if object_id_to_player_class[res]!=0 then --object to be deleted is a player
  659.        player_delete(object_id_to_player_class[res])
  660.        object_id_to_player_class[res]=0
  661.      end if
  662.      --end new optimized code
  663.  
  664.      --old code not very fast trying optimzing
  665.      --index=0
  666.      --for j=1 to length(player_list) do
  667.      -- if player_list[j][1]=res then
  668.      --   index=j
  669.           --for k=1 to length(player_list[j][2]) do
  670.           --    if player_list[j][2][k][1]=31 then
  671.           --      puts(1,"player has left "&player_list[j][2][k][3]&"\n")
  672.           --      exit
  673.          --     end if
  674.          -- end for
  675.      --   exit
  676.      -- end if
  677.      --end for
  678.      --if index!=0 then
  679.      -- player_list=remove_line(player_list,index)
  680.      --end if
  681.      --end old code
  682.    
  683.   end for
  684.  
  685.   --UPDATEATT = 11;
  686.   temp=reverse(int_to_bytes(length("")+5)) &11
  687.   --write=arcfour_encrypt_block2(write)
  688.   send_buffer=append(send_buffer,{temp})
  689. end procedure
  690.  
  691. procedure global_notification_read()
  692.    object res
  693.     --puts(1,"global_notification \n")
  694.     res=input_stream_readint(inputstream)
  695.     res=input_stream_readutf(inputstream)
  696. end procedure
  697.  
  698. procedure accountlist_read()
  699.   object res
  700.   res=input_stream_readint(inputstream)
  701.   res=input_stream_readshort(inputstream)
  702.   for i=0 to res-1 do
  703.     res=input_stream_readint(inputstream)
  704.   end for
  705. end procedure
  706.  
  707. procedure show_effect_read()
  708.   object res
  709.   res=input_stream_readbyte(inputstream)
  710.   res=input_stream_readint(inputstream)
  711.   res=location_new_from_input(inputstream)
  712.   location_delete(res)
  713.   res=location_new_from_input(inputstream)
  714.   location_delete(res)
  715.   res=input_stream_readint(inputstream)
  716. end procedure
  717.  
  718. procedure allyshoot_read()
  719.   object res
  720.   res=input_stream_readbyte(inputstream)
  721.   res=input_stream_readint(inputstream)
  722.   res=input_stream_readshort(inputstream)
  723.   res=input_stream_readint(inputstream)
  724. end procedure
  725.  
  726. procedure notification_read()
  727.   object res
  728.   res=input_stream_readint(inputstream)
  729.   res=input_stream_readutf(inputstream)
  730.   res=input_stream_readint(inputstream)
  731. end procedure
  732.  
  733. procedure new_tick_read()
  734.   integer size,tick_id
  735.   object res
  736.   sequence temp,write,temp2
  737.  
  738.   --new code optimizeation
  739.   integer object_id
  740.   sequence position
  741.   integer class
  742.  
  743.   tick_id=input_stream_readint(inputstream)
  744.   res=input_stream_readint(inputstream)
  745.   size=input_stream_readshort(inputstream)
  746.  
  747.   for i=0 to size-1 do
  748.     res=object_status_data_new_from_input(inputstream)
  749.    
  750.     temp=object_status_data_get(res)
  751.  
  752.     --new optimize code
  753.     object_id=temp[1]
  754.     if object_id_to_player_class[object_id]!=0 then --object to be updated is a player
  755.       position=location_get(temp[2])
  756.       player_update( object_id_to_player_class[object_id],temp[3],position, {convert3dspaceto2d(position[1]),convert3dspaceto2d(position[2]) } )
  757.     end if
  758.     --end new optimized code
  759.  
  760.     --old code
  761.     --player --stats updae
  762.     --for j=1 to length(player_list) do
  763.     --  if player_list[j][1]=temp[1] then
  764.     --    player_list[j][3]=location_get(temp[2])
  765.     --    for k=1 to length(temp[3]) do
  766.     --        temp2=stat_data_get(temp[3][k])
  767.     --        for l=1 to length(player_list[j][2]) do
  768.     --          if player_list[j][2][l][1]=temp2[1] then
  769.     --           player_list[j][2][l]=temp2
  770.     --         exit
  771.     --          end if
  772.     --        end for
  773.     --    end for
  774.    
  775.     --  exit   
  776.     --  end if
  777.     --end for
  778.     --player stats update--
  779.     --old code
  780.  
  781.     object_status_data_delete(res)
  782.   end for
  783.  
  784.   if size!=0 then
  785.     current_tick=tick_id
  786.   end if
  787.  
  788.   write=""
  789.   write=writeint(write,current_tick) --tick id
  790.   write=writeint(write,current_time()) --time
  791.   --position
  792.   write=writefloat(write,my_position[1])
  793.   write=writefloat(write,my_position[2])
  794.  
  795.   write=writeshort(write,0)
  796.   --Move = 7;
  797.   temp=reverse(int_to_bytes(length(write)+5)) &7
  798.   write=arcfour_encrypt_block2(write)
  799.   send_buffer=append(send_buffer,{temp&write})
  800.  
  801. end procedure
  802.  
  803. procedure text_read()
  804.   object res
  805.   integer object_id
  806.   res=input_stream_readutf(inputstream)
  807.   object_id=input_stream_readint(inputstream)
  808.   res=input_stream_readint(inputstream)
  809.   res=input_stream_readbyte(inputstream)
  810.   res=input_stream_readutf(inputstream)
  811.   res=input_stream_readutf(inputstream)
  812.   --puts(1,res&"\n")
  813.   if object_id!=4294967295 then
  814.      player_message_set(object_id_to_player_class[object_id],{res,33*12})
  815.   end if
  816.  
  817.   res=input_stream_readutf(inputstream)
  818.  
  819.   --    this.name_ = badi.readUTF(); // UTF
  820.     --  this.objectId_ = badi.readInt(); // Int
  821.     --  this.numStars_ = badi.readInt(); // Int
  822.     --  this.bubbleTime_ = badi.readUnsignedByte(); // UnsignedByte
  823.     --  this.recipient_ = badi.readUTF(); // UTF
  824.     --  this.text_ = badi.readUTF(); // UTF
  825.     --  this.cleanText_ = badi.readUTF(); // UTF
  826. end procedure
  827.  
  828. procedure ping_read()
  829.   object res
  830.   sequence write,temp
  831.   res=input_stream_readint(inputstream)
  832.  
  833.   write=""
  834.   write=writeint(write,res) --serial
  835.   write=writeint(write,current_time()) --time
  836.  
  837.   --PONG = 16;
  838.   temp=reverse(int_to_bytes(length(write)+5)) &16
  839.   write=arcfour_encrypt_block2(write)
  840.   send_buffer=append(send_buffer,{temp&write})
  841.  
  842. end procedure
  843.  
  844. procedure goto_packet_read()
  845.   object res
  846.   sequence write,temp
  847.   res=input_stream_readint(inputstream)
  848.   res=location_new_from_input(inputstream)
  849.   location_delete(res)
  850.  
  851.   write=""
  852.   write=writeint(write,current_time()) --time
  853.  
  854.   temp=reverse(int_to_bytes(length(write)+5)) &14
  855.   write=arcfour_encrypt_block2(write)
  856.   send_buffer=append(send_buffer,{temp&write})
  857. end procedure
  858.  
  859. procedure shoot_packet_read()
  860.   object res
  861.   res=input_stream_readbyte(inputstream)
  862.   res=input_stream_readint(inputstream)
  863.   res=input_stream_readint(inputstream)
  864.   res=location_new_from_input(inputstream)
  865.   location_delete(res)
  866.   res=input_stream_readint(inputstream)
  867.   res=input_stream_readshort(inputstream)
  868. end procedure
  869.  
  870. procedure play_sound_read()
  871.   object res
  872.   res=input_stream_readint(inputstream)
  873.   res=input_stream_readbyte(inputstream)
  874. end procedure
  875.  
  876. procedure traderequest_packet_read()
  877.   object res
  878.   sequence data,temp
  879.   data={}
  880.   res=input_stream_readutf(inputstream)
  881.   puts(1,"trade requested "&res&"\n")
  882.  
  883.  
  884.   --send_buffer=append(send_buffer,{useportal_packet_write(503)})
  885.   --automaticly trade upon request
  886.   --data=writeutf(data,res)
  887.   --temp=reverse(int_to_bytes(length(data)+5)) &21
  888.   --data=arcfour_encrypt_block2(data)
  889.   --send_buffer=append(send_buffer,{temp&data})
  890.  
  891. end procedure
  892.  
  893. procedure tradestart_packet_read()
  894.   object res
  895.   integer size
  896.   atom item,bt,eq,included
  897.   size=input_stream_readshort(inputstream)
  898.  
  899.   for i=0 to size-1 do
  900.     item=input_stream_readint(inputstream)
  901.     bt=input_stream_readint(inputstream)
  902.     eq=input_stream_readbool(inputstream)
  903.     included=input_stream_readbool(inputstream)
  904.     my_items=append(my_items,{item,bt,eq,included})
  905.   end for
  906.  
  907.   puts(1,"my items\n")
  908.   ?my_items
  909.  
  910.   res=input_stream_readutf(inputstream)
  911.   size=input_stream_readshort(inputstream)
  912.  
  913.   for i=0 to size-1 do
  914.     item=input_stream_readint(inputstream)
  915.     bt=input_stream_readint(inputstream)
  916.     eq=input_stream_readbool(inputstream)
  917.     included=input_stream_readbool(inputstream)
  918.     there_items=append(there_items,{item,bt,eq,included})
  919.   end for
  920.   puts(1,"there items\n")
  921.   ?there_items
  922.  
  923. end procedure
  924.  
  925. procedure tradedone_packet_read()
  926.   object res
  927.   res=input_stream_readint(inputstream)
  928.   res=input_stream_readutf(inputstream)
  929.   puts(1,"tradedone "&res&"\n")
  930. end procedure
  931.  
  932. procedure tradechanged_packet_read()
  933.   integer size
  934.   object res
  935.   sequence items
  936.   items={}
  937.   size=input_stream_readshort(inputstream)
  938.   for i=0 to size-1 do
  939.     res=input_stream_readbool(inputstream)
  940.     items&=res
  941.   end for
  942.   ?items
  943. end procedure
  944.  
  945. procedure clientstat_packet_read()
  946.   object res
  947.   res=input_stream_readutf(inputstream)
  948.   puts(1,res&"\n")
  949.   res=input_stream_readint(inputstream)
  950.  
  951. end procedure
  952.  
  953. procedure reconnect_packet_read()
  954.   object res
  955.   integer size
  956.   res=input_stream_readutf(inputstream)
  957.   puts(1,"name "&res&"\n")
  958.   res=input_stream_readutf(inputstream)
  959.   puts(1,"host"&res&"\n")
  960.   res=input_stream_readint(inputstream)
  961.   puts(1,"port ")
  962.   ?res
  963.   puts(1,"\n")
  964.   res=input_stream_readint(inputstream)
  965.   puts(1,"game id")
  966.   ?res
  967.   puts(1,"\n")
  968.   res=input_stream_readint(inputstream)
  969.   puts(1,"key time")
  970.   ?res
  971.   size=input_stream_readshort(inputstream)
  972.   ?size
  973.   res=input_stream_readfully(inputstream,size)
  974.   ?res
  975.   --this.name_ = badi.readUTF(); // UTF
  976.   --this.host_ = badi.readUTF(); // UTF
  977.     --  this.port_ = badi.readInt(); // Int
  978.     --  this.gameId_ = badi.readInt(); // Int
  979.     --  this.keyTime_ = badi.readInt(); // Int
  980.     --  short size = badi.readShort();
  981.     --  this.key_ = new byte[size];
  982.     --  badi.readFully(key_);
  983.  
  984. end procedure
  985.  
  986.  
  987. procedure read_packet()
  988.   integer packet_id,packet_len,temp
  989.   sequence data
  990.   object res
  991.  
  992.   --puts(1,"location class size "&sprint(location_classsize())&"\n")
  993.   --puts(1,"object_status class size "&sprint(object_status_classsize())&"\n")
  994.   --puts(1,"object_status_data class size "&sprint(object_status_data_classsize())&"\n")
  995.   --puts(1,"stat_data class size "&sprint(stat_data_classsize())&"\n")
  996.   --puts(1,"tile class size "&sprint(tile_classsize())&"\n")
  997.  
  998.   --puts(1,"size of  player_class_list "&sprint(length(player_class_list))&"\n")
  999.  
  1000.   while 1 do
  1001.    
  1002.  
  1003.   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
  1004.   else
  1005.     for i=1 to length(send_buffer) do
  1006.        temp=WsockSendData(Server_sock,send_buffer[i][1])
  1007.      end for
  1008.      send_buffer={}
  1009.     exit
  1010.   end if
  1011.  
  1012.   packet_id=input_stream_peek(inputstream,5)
  1013.   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)} )
  1014.    
  1015.   --puts(1,"packet id\n")
  1016.   --?packet_id
  1017.  
  1018.   if input_stream_length(inputstream)>5 then
  1019.     data=arcfour_decrypt_block(input_stream_slice(inputstream,6,packet_len))
  1020.    
  1021.     input_stream_set(inputstream, input_stream_slice(inputstream,packet_len+1, input_stream_length(inputstream) ) )
  1022.     input_stream_set(inputstream, data&input_stream_get(inputstream))
  1023.    
  1024.   end if
  1025.  
  1026.   if packet_id=fail_packet then
  1027.     puts(1,"fail ")
  1028.     ?input_stream_readint(inputstream)
  1029.     puts(1,input_stream_readutf(inputstream)&"\n")
  1030.   elsif packet_id=ping_packet then
  1031.     ping_read()
  1032.   elsif packet_id=tradedone_packet then
  1033.     tradedone_packet_read()
  1034.   elsif packet_id=shoot_packet then
  1035.     shoot_packet_read()
  1036.   elsif packet_id=global_notification_packet then
  1037.     global_notification_read()
  1038.   elsif packet_id=play_sound_packet then
  1039.     play_sound_read()
  1040.   elsif packet_id=create_suc_packet then
  1041.     create_suc_packet_read()
  1042.   elsif packet_id=tradechanged_packet then
  1043.     tradechanged_packet_read()
  1044.   elsif packet_id=accountlist_packet then
  1045.     accountlist_read()
  1046.   elsif packet_id=goto_packet then
  1047.     goto_packet_read()
  1048.   elsif packet_id= show_effect_packet then
  1049.     show_effect_read()
  1050.   elsif packet_id= text_packet then
  1051.     text_read()
  1052.   elsif packet_id=reconnect_packet then
  1053.     reconnect_packet_read()
  1054.   elsif packet_id=update_packet then
  1055.     update_packet_read()
  1056.   elsif packet_id= new_tick_packet then
  1057.     new_tick_read()
  1058.   elsif packet_id=tradestart_packet then
  1059.     tradestart_packet_read()
  1060.   elsif packet_id= traderequest_packet then
  1061.     traderequest_packet_read()
  1062.   elsif packet_id=  notification_packet then
  1063.      notification_read()
  1064.   elsif packet_id=mapinfo_packet then
  1065.     mapinfo_packet_read()
  1066.   elsif packet_id=  allyshoot_packet then
  1067.     allyshoot_read()
  1068.   elsif packet_id=clientstat_packet then
  1069.     clientstat_packet_read()
  1070.   else
  1071.     ?packet_id
  1072.     puts(1,"unknow packet\n")
  1073.     sleep(100)
  1074.   end if
  1075.  
  1076.   end while
  1077. end procedure
  1078.  
  1079. procedure processServerMessage(atom hWnd, atom arg1, atom arg2)
  1080.   atom      index, newsock
  1081.   integer   action, sock, iwork
  1082.   object    owork,junk
  1083.   sequence  newIP,swork,rx,tx
  1084.   sequence  data
  1085.  
  1086.   action = lo_word(arg2)
  1087.   sock = arg1
  1088.  
  1089.   if action=FD_CONNECT then
  1090.     puts(1,"connected\n")
  1091.     iwork=WsockSendData(sock,hello_packet_write())
  1092.     --iwork=WsockSendData(sock,create_packet_write())
  1093.     iwork=WsockSendData(sock,load_packet_write())
  1094.   elsif action = FD_READ then
  1095.     rx = ""
  1096.     owork = WsockReadData(sock,1)
  1097.     while sequence(owork) do
  1098.       rx = rx & owork
  1099.       owork = WsockReadData(sock,1)
  1100.     end while
  1101.     if length(rx) > 0 then
  1102.  
  1103.       input_stream_append(inputstream,rx)
  1104.  
  1105.       if input_stream_length(inputstream)>5 then
  1106.         --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" )
  1107.         --puts(1,"packet id:"&sprint(input_stream_peek(inputstream,5))&"\n")
  1108.  
  1109.         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
  1110.           read_packet()
  1111.         end if
  1112.       end if
  1113.  
  1114.     end if
  1115.   elsif action = FD_CLOSE then
  1116.      puts(1,"server closed\n")
  1117.      WsockCloseSocket(sock)
  1118.      --setTimer(Window1,1002,1000*60)
  1119.   end if
  1120. end procedure
  1121.  
  1122. --old code obslete keeped for reseaons unknow
  1123. procedure main_loop()
  1124. integer temp
  1125. atom t_start,t_end
  1126.  
  1127.    while running=1 do
  1128.      for i=1 to 1000 do
  1129.         doEvents(0)
  1130.      end for
  1131.  
  1132.      t_start=get_tick_count()
  1133.  
  1134.      if input_stream_length(inputstream)>5 then
  1135.         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
  1136.           --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" )
  1137.           --puts(1,"packet id:"&sprint(input_stream_peek(inputstream,5))&"\n")
  1138.           read_packet()
  1139.         end if
  1140.       end if
  1141.  
  1142.      for i=1 to length(send_buffer) do
  1143.        --?send_buffer[i][1]
  1144.        --puts(1,"\n")
  1145.        temp=WsockSendData(Server_sock,send_buffer[i][1])
  1146.      end for
  1147.      send_buffer={}
  1148.  
  1149.      t_end=get_tick_count()
  1150.  
  1151.      if 100-(t_end-t_start)>=1 then
  1152.         --usleep(100-(t_end-t_start))  
  1153.      end if
  1154.  
  1155.      --puts(1,"time "&sprint(t_end-t_start)&"\n")
  1156.    end while
  1157.  
  1158.    abort(0)
  1159.  
  1160. end procedure
  1161. setTimer(Window1,1001,1000)
  1162.  
  1163. setTimer(Window1,1010,30)
  1164.  
  1165.  
  1166. --==============================CWindow1 events==============================--
  1167.  
  1168.  
  1169. procedure draw_text_bubble(integer x, integer y,sequence text)
  1170.   sequence messages
  1171.   integer pixelw,pos1,upy
  1172.   messages={}
  1173.   pos1=1
  1174.   pixelw=0
  1175.  
  1176.   for i=1 to length(text) do
  1177.     pixelw+=text_sizes[ text[i] ]
  1178.     if pixelw>=200 then
  1179.       messages=append(messages,text[pos1..i])
  1180.       pos1=i+1
  1181.       pixelw=0
  1182.     end if
  1183.   end for
  1184.  
  1185.   if length(messages) then
  1186.     if pixelw>0 then
  1187.        messages=append(messages,text[pos1..length(text)])
  1188.     end if
  1189.     upy=floor(pixelh*length(messages))
  1190.  
  1191.     allegro:rectfill(buffer,x,y-upy,x+200,y,makecol(0,0,192))
  1192.     allegro:rect(buffer,x,y-upy,x+200,y,makecol(0,192,0))
  1193.     for i=1 to length(messages) do
  1194.        allegro:textout_ex(buffer,font, messages[i], x, (y+(pixelh*i)-pixelh)-upy , makecol(0,0,0), -1 )
  1195.     end for
  1196.   else
  1197.     upy=floor(pixelh*1)
  1198.     allegro:rectfill(buffer,x,y-upy,x+pixelw,y,makecol(0,0,192))
  1199.     allegro:rect(buffer,x,y-upy,x+pixelw,y,makecol(0,192,0))
  1200.     allegro:textout_ex(buffer,font, text, x, (y+(pixelh*1)-pixelh)-upy , makecol(0,0,0), -1 )  
  1201.   end if
  1202.  
  1203. end procedure
  1204.  
  1205. procedure cwindow1_paint()
  1206.   atom hdc
  1207.   atom x,y
  1208.   sequence float
  1209.   integer mapx,mapy
  1210.   hdc=getDC(CWindow1)
  1211.   clear_to_color(buffer,color_background)
  1212.  
  1213.   --allegro:line(buffer,-view_left,-view_top,workspace_width-view_left,workspace_height-view_top,color_black)
  1214.   allegro:rect(buffer,0-view_left,0-view_top,800-view_left,600-view_top,color_red)
  1215.   --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 )
  1216.   --allegro:textout_ex(buffer,font, sprint(view_left)&" "&sprint(view_top), 0 , 0 , makecol(255,0,0),-1 )
  1217.   --allegro:textout_ex(buffer,font, sprint(view_top)&" "&sprint(window_height)&" "&sprint(view_top+window_height) ,100 , 100 , makecol(255,0,0),-1 )
  1218.  
  1219.   if key_check(VK_LEFT)=1 then
  1220.     my_position[1]-=0.10
  1221.     my_position_real[1]-=0.10
  1222.   elsif key_check(VK_RIGHT)=1 then
  1223.     my_position[1]+=0.10
  1224.     my_position_real[1]+=0.10
  1225.   end if
  1226.  
  1227.   if key_check(VK_UP)=1 then
  1228.     my_position[2]-=0.10
  1229.     my_position_real[2]-=0.10
  1230.   elsif key_check(VK_DOWN)=1 then
  1231.     my_position[2]+=0.10
  1232.     my_position_real[2]+=0.10
  1233.   end if
  1234.  
  1235.   if length(my_position)!=0 then
  1236.     --view_left=convert3dspaceto2d(my_position[1])-400
  1237.     --view_top=convert3dspaceto2d(my_position[2])-300
  1238.     view_left=convert3dspaceto2d(my_position_real[1])-400
  1239.     view_top=convert3dspaceto2d(my_position_real[2])-300
  1240.   end if
  1241.  
  1242.   mapx=floor(view_left/space3dto2d)
  1243.   mapy=floor(view_top/space3dto2d)
  1244.   --800/32 ==25
  1245.   --600/32 ==18.75
  1246.  
  1247.   if length(map_data) then
  1248.    
  1249.   --puts(1,"view_left "&sprint(view_left)&"\n")
  1250.  
  1251.   --puts(1,"view_top "&sprint(view_top)&"\n")
  1252.   for yy=mapy to mapy+19 do
  1253.     for xx=mapx to mapx+25 do
  1254.       if xx>0 and yy>0 then
  1255.         if map_data[yy][xx]=122 then
  1256.           --puts(1,"found\n")
  1257.           draw_sprite(buffer,tile_bitmaps[1], (xx*space3dto2d)-view_left,(yy*space3dto2d)-view_top)
  1258.         elsif map_data[yy][xx]=58 then
  1259.           draw_sprite(buffer,tile_bitmaps[2], (xx*space3dto2d)-view_left,(yy*space3dto2d)-view_top)
  1260.         elsif map_data[yy][xx]=121 then
  1261.           draw_sprite(buffer,tile_bitmaps[3], (xx*space3dto2d)-view_left,(yy*space3dto2d)-view_top)
  1262.         end if
  1263.    
  1264.       end if
  1265.     end for
  1266.   end for
  1267.  
  1268.   end if
  1269.  
  1270.   for i=1 to length(player_class_list) do
  1271.     if length(player_class_list[i]) then
  1272.       if player_class_list[i][1]!=my_object_id then
  1273.         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)
  1274.         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 )
  1275.       else
  1276.         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)
  1277.         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 )
  1278.       end if
  1279.     end if
  1280.   end for
  1281.  
  1282.   for i=1 to length(player_class_list) do
  1283.     if length(player_class_list[i]) then
  1284.     if player_class_list[i][7][2]>0 then
  1285.       player_class_list[i][7][2]-=1
  1286.       --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)
  1287.       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])
  1288.       --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 )
  1289.     end if
  1290.     end if
  1291.   end for
  1292.  
  1293.  
  1294.   blit_to_hdc(buffer,hdc,0,0,0,0,window_width,window_height)
  1295.   releaseDC(hdc)
  1296. end procedure
  1297.  
  1298. procedure cwindow1_resize()
  1299. sequence size
  1300.  size=getCtlSize( Window1 )
  1301.  
  1302.  --view width\height
  1303.  window_width=size[1]
  1304.  window_height=size[2]-(window_titlebar_height+20)
  1305.  destroy_bitmap(buffer)
  1306.  
  1307.  buffer=0--might catch a bug
  1308.  if window_width>workspace_width then
  1309.     window_width=workspace_width
  1310.  end if
  1311.  if window_height>workspace_height then
  1312.     window_height=workspace_height
  1313.  end if
  1314.  if window_width<1 then
  1315.     window_width=1
  1316.  end if
  1317.  if window_height<1 then
  1318.     window_height=1
  1319.  end if
  1320.  
  1321.  buffer=create_bitmap(window_width,window_height)
  1322.  
  1323. end procedure
  1324.  
  1325. --------------------------------------------------------------------------------
  1326. procedure Window1_onClose (integer self, integer event, sequence params)--params is ()
  1327.   running=0
  1328.   WsockCloseSocket(Server_sock)
  1329.   close_allegro()
  1330.   --returnValue(-1)
  1331.  
  1332. end procedure
  1333. setHandler( Window1, w32HClose, routine_id("Window1_onClose"))
  1334. --------------------------------------------------------------------------------
  1335. procedure Window1_onEvent (integer self, integer event, sequence params)--params is ( int iMsg, atom wParm, atom lParm )
  1336.   if params[1] = SM_ASYNC then
  1337.     processServerMessage(hWndMainWindow,params[2],params[3])
  1338.   end if
  1339. end procedure
  1340. setHandler( Window1, w32HEvent, routine_id("Window1_onEvent"))
  1341. --------------------------------------------------------------------------------
  1342. procedure Window1_onKeyDown (integer self, integer event, sequence params)--params is ( atom scanCode, atom shift )
  1343.   key_add(params[1])
  1344. end procedure
  1345. setHandler( Window1, w32HKeyDown, routine_id("Window1_onKeyDown"))
  1346. --------------------------------------------------------------------------------
  1347. procedure Window1_onKeyUp (integer self, integer event, sequence params)--params is ( int scanCode, int shift )
  1348.   key_remove(params[1])
  1349. end procedure
  1350. setHandler( Window1, w32HKeyUp, routine_id("Window1_onKeyUp"))
  1351. --------------------------------------------------------------------------------
  1352. procedure Window1_onOpen (integer self, integer event, sequence params)--params is ()
  1353.   integer iwork, port
  1354.   sequence swork,ip
  1355.  
  1356.   port = 2050
  1357.  
  1358.   iwork = WsockInit()
  1359.   if iwork = -1 then -- WinSock failed
  1360.     iwork = message_box("WSockInit() failed!","Error",MB_TASKMODAL + MB_ICONSTOP + MB_OK)
  1361.     abort(99)
  1362.   end if
  1363.  
  1364.  
  1365.   hWndMainWindow = getHandle(Window1)
  1366.  
  1367.   --blocking connect, might need to make this none blocking
  1368.   --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}))
  1369.   Server_sock=Wsock_new("50.18.113.133", 2050 , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
  1370.  
  1371.   --Server_sock=Wsock_new("127.0.0.1", 2050 , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
  1372.  
  1373.   --Server_sock=WsockSocket(AF_INET,SOCK_STREAM)
  1374.  
  1375.   --if WSAAsyncSelect(Server_sock,hWndMainWindow,SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))!=0 then
  1376.   --    puts(1,"WSAAsyncSelect error\n")
  1377.   --end if
  1378.  
  1379.   --ip=WsockHostInfo("ec2-176-34-195-206.eu-west-1.compute.amazonaws.com")
  1380.   --puts(1,ip[2])
  1381.  
  1382.   --?WsockConnectAsync(Server_sock,2050,ip[2])
  1383.  
  1384.   --Server = WsockListenAsync(port, hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_ACCEPT,FD_CLOSE,FD_WRITE}))
  1385.  
  1386.   --if Server_sock = SOCKET_ERROR then  -- WinSock failed
  1387.   --  iwork = message_box("WsockListenAsync() failed!","Error",MB_TASKMODAL+MB_ICONSTOP+MB_OK)
  1388.   --  abort(99)
  1389.   --end if
  1390.   startup_allegro()
  1391.  
  1392. end procedure
  1393. setHandler( Window1, w32HOpen, routine_id("Window1_onOpen"))
  1394. --------------------------------------------------------------------------------
  1395. procedure Window1_onResize (integer self, integer event, sequence params)--params is ( int style, int cx, int cy )
  1396.   sequence size
  1397.   size=getCtlSize(Window1)
  1398.   setCtlSize(CWindow1,size[1],size[2]-(window_titlebar_height))
  1399. end procedure
  1400. setHandler( Window1, w32HResize, routine_id("Window1_onResize"))
  1401. --------------------------------------------------------------------------------
  1402. procedure Window1_onTimer (integer self, integer event, sequence params)--params is ( int timerId)
  1403.   if params[1]=1001 then
  1404.     killTimer(Window1,1001)
  1405.     --main_loop()
  1406.   elsif params[1]=1002 then
  1407.     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}))
  1408.   elsif params[1]=1010 then
  1409.     setTimer(CWindow1,1001,10)
  1410.   end if
  1411. end procedure
  1412. setHandler( Window1, w32HTimer, routine_id("Window1_onTimer"))
  1413. --------------------------------------------------------------------------------
  1414. procedure CWindow1_onOpen (integer self, integer event, sequence params)--params is ()
  1415.   setTimer(CWindow1,1001,100)
  1416. end procedure
  1417. setHandler( CWindow1, w32HOpen, routine_id("CWindow1_onOpen"))
  1418. --------------------------------------------------------------------------------
  1419. procedure CWindow1_onPaint (integer self, integer event, sequence params)--params is ( int x1, int y1, int x2, int y2 )
  1420.   setTimer(CWindow1,1001,0)
  1421. end procedure
  1422. setHandler( CWindow1, w32HPaint, routine_id("CWindow1_onPaint"))
  1423. --------------------------------------------------------------------------------
  1424. procedure CWindow1_onResize (integer self, integer event, sequence params)--params is ( int style, int cx, int cy )
  1425.   cwindow1_resize()
  1426. end procedure
  1427. setHandler( CWindow1, w32HResize, routine_id("CWindow1_onResize"))
  1428. --------------------------------------------------------------------------------
  1429. procedure CWindow1_onTimer (integer self, integer event, sequence params)--params is ( int timerId)
  1430.   if params[1]=1001 then
  1431.     cwindow1_paint()
  1432.     killTimer(CWindow1,1001)
  1433.   end if
  1434. end procedure
  1435. setHandler( CWindow1, w32HTimer, routine_id("CWindow1_onTimer"))
  1436.  
  1437.  
  1438. WinMain( Window1,Normal )
  1439. --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