Advertisement
poosh

ScrnClientPerkRepLink

Jul 16th, 2014
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ScrnClientPerkRepLink extends ClientPerkRepLink;
  2.  
  3. var byte TotalCategories;
  4. var int TotalWeapons, TotalChars;
  5.  
  6. var String CurrentJob; // for debug purposes
  7.  
  8. // how many more records client is expecting to receive from the server
  9. // used on client-side only
  10. var byte PendingItems;
  11.  
  12. replication
  13. {
  14.     reliable if ( bNetOwner && bNetInitial && Role == ROLE_Authority )
  15.         TotalWeapons, TotalChars, TotalCategories;
  16.  
  17.     reliable if ( Role < ROLE_Authority )
  18.         ServerStartInitialReplication;
  19. }
  20.  
  21.  
  22. simulated function PostNetBeginPlay()
  23. {
  24.     super.PostNetBeginPlay();
  25.    
  26.     if ( Role < ROLE_Authority ) {
  27.         ShopCategories.Length = TotalCategories;
  28.         ShopInventory.Length = TotalWeapons;
  29.         CustomChars.Length = TotalChars;
  30.         PendingItems = TotalCategories + TotalWeapons + TotalChars;
  31.         // tell server that we are ready to receive data
  32.         ServerStartInitialReplication();
  33.         GotoState('ReceivingData');
  34.     }
  35. }
  36.  
  37.  
  38. function ServerStartInitialReplication()
  39. {
  40.     GotoState('InitialReplication');
  41. }
  42.  
  43. function ServerRequestCategories(byte Index, byte Count)
  44. {
  45.     local byte end;
  46.    
  47.     if( NextRepTime<Level.TimeSeconds )
  48.         return ;
  49.        
  50.     end = min(ShopCategories.Length, Index + Count);
  51.     while ( Index < end )  
  52.         ClientReceiveCategory(Index, ShopCategories[Index]);
  53.     NextRepTime = Level.TimeSeconds+2.f;
  54. }
  55.  
  56. function ServerRequestWeapons(int Index, byte Count)
  57. {
  58.     local int end;
  59.    
  60.     if( NextRepTime<Level.TimeSeconds )
  61.         return ;
  62.        
  63.     end = min(ShopInventory.Length, Index + Count);
  64.     while ( Index < end )  
  65.         ClientReceiveWeapon(Index, ShopInventory[Index].PC, ShopInventory[Index].CatNum);
  66.     NextRepTime = Level.TimeSeconds+2.f;
  67. }
  68.  
  69.  
  70. function ServerRequestChars(int Index, byte Count)
  71. {
  72.     local int end;
  73.    
  74.     if( NextRepTime<Level.TimeSeconds )
  75.         return ;
  76.        
  77.     end = min(CustomChars.Length, Index + Count);
  78.     while ( Index < end )  
  79.         ClientReceiveChar(CustomChars[Index], Index);
  80.     NextRepTime = Level.TimeSeconds+2.f;
  81. }
  82.  
  83. simulated function ClientReceiveCategory( byte Index, FShopCategoryIndex S )
  84. {  
  85.     if ( ShopCategories[Index].Name=="" )
  86.         PendingItems--;
  87.        
  88.     super.ClientReceiveCategory(Index, S);
  89. }  
  90.  
  91. simulated function ClientReceiveWeapon( int Index, class<Pickup> P, byte Categ )
  92. {  
  93.     if ( ShopInventory[Index].PC==None )
  94.         PendingItems--;
  95.  
  96.     super.ClientReceiveWeapon(Index, P, Categ);
  97. }
  98.    
  99. simulated function ClientReceiveChar( string CharName, int Num )
  100. {
  101.     if ( CustomChars[Num] == "" ) {
  102.         PendingItems--;
  103.         ClientAckSkinNum++;
  104.     }
  105.     CustomChars[Num] = CharName;
  106. }
  107.  
  108. simulated function ClientReceiveTag( Texture T, string Tag, bool bInCaps )
  109. {
  110.     local PlayerController PC;
  111.    
  112.     super.ClientReceiveTag(T, Tag, bInCaps);
  113.  
  114.     // todo: add delay before upating the HUD (wait for more incoming smiletags)
  115.     PC = Level.GetLocalPlayerController();
  116.     if( PC!=None && SRHUDKillingFloor(PC.MyHUD)!=None )
  117.         SRHUDKillingFloor(PC.MyHUD).SmileyMsgs = SmileyTags;    
  118. }
  119.  
  120. simulated function ClientSendAcknowledge()
  121. {
  122.     ServerAcnowledge(ClientAccknowledged[0],ClientAccknowledged[1]);
  123.     ServerAckSkin(ClientAckSkinNum);
  124. }
  125.  
  126. // client state
  127. simulated state ReceivingData
  128. {
  129.     simulated function BeginState()
  130.     {
  131.         if ( Level.NetMode != NM_Client ) {
  132.             GotoState(''); // just in case          
  133.             return;
  134.         }
  135.         SetTimer(10.0, true); // give server reasonable time to send us data
  136.         CurrentJob = "Receiving Data";
  137.     }
  138.    
  139.     simulated function EndState()
  140.     {
  141.         SetTimer(0, false);
  142.     }
  143.    
  144.     simulated function Timer()
  145.     {
  146.         CheckData();
  147.     }    
  148.    
  149.     simulated function CheckData()
  150.     {
  151.         local int i, j;
  152.        
  153.         // weapon categories
  154.         CurrentJob = "Receiving Categories";
  155.         for ( i=0; i<ShopCategories.Length; ++i ) {
  156.             if ( ShopCategories[i].Name == "") {
  157.                 // check if we need more categories in a row
  158.                 j = i+1;
  159.                 while ( j<ShopCategories.Length && ShopCategories[j].Name == "" )
  160.                     ++j;
  161.                 PendingItems = j-i;
  162.                 ServerRequestCategories(i, PendingItems);
  163.                 SetTimer(2.0, true);
  164.                 return;
  165.             }
  166.         }
  167.        
  168.         // weapons
  169.         CurrentJob = "Receiving Weapons";
  170.         for ( i=0; i<ShopInventory.Length; ++i ) {
  171.             if ( ShopInventory[i].PC == none) {
  172.                 // check if we need more categories in a row
  173.                 j = i+1;
  174.                 while ( j<ShopInventory.Length && ShopInventory[j].PC == none )
  175.                     ++j;
  176.                 PendingItems = j-i;
  177.                 ServerRequestWeapons(i, PendingItems);
  178.                 SetTimer(2.0, true);
  179.                 return;
  180.             }
  181.         }
  182.  
  183.         // if we reached here, then client received all categories and weapons
  184.         if ( !bRepCompleted ) {
  185.             // call it before receiving custom characters  
  186.             ClientAllReceived();
  187.             // tell server that we've got all weapons
  188.             ServerAcnowledge(ClientAccknowledged[0],ClientAccknowledged[1]);
  189.         }
  190.  
  191.         // characters
  192.         CurrentJob = "Receiving Characters";
  193.         for ( i=0; i<CustomChars.Length; ++i ) {
  194.             if ( CustomChars[i] == "") {
  195.                 // check if we need more categories in a row
  196.                 j = i+1;
  197.                 while ( j<CustomChars.Length && CustomChars[j] == "" )
  198.                     ++j;
  199.                 PendingItems = j-i;
  200.                 ServerRequestChars(i, PendingItems);
  201.                 SetTimer(2.0, true);
  202.                 return;
  203.             }
  204.         }  
  205.         ServerAckSkin(CustomChars.Length); // tell server that we've got all characters
  206.        
  207.         CurrentJob = "ALL OK";
  208.         GotoState('');
  209.     }
  210.    
  211.     simulated function ClientReceiveCategory( byte Index, FShopCategoryIndex S )
  212.     {  
  213.         global.ClientReceiveCategory(Index, S);
  214.         if ( PendingItems > 0 )
  215.             SetTimer(1.0, true); // take a little pause before checking - more items should come from server
  216.         else
  217.             CheckData(); // no pending items left, check now
  218.     }  
  219.  
  220.     simulated function ClientReceiveWeapon( int Index, class<Pickup> P, byte Categ )
  221.     {  
  222.         global.ClientReceiveWeapon(Index, P, Categ);
  223.         if ( PendingItems > 0 )
  224.             SetTimer(1.0, true); // take a little pause before checking - more items should come from server
  225.         else
  226.             CheckData(); // no pending items left, check now    
  227.     }
  228.    
  229.     simulated function ClientReceiveChar( string CharName, int Num )
  230.     {
  231.         global.ClientReceiveChar(CharName, Num);
  232.         if ( PendingItems > 0 )
  233.             SetTimer(1.0, true); // take a little pause before checking - more items should come from server
  234.         else
  235.             CheckData(); // no pending items left, check now    
  236.     }
  237. }
  238.  
  239.  
  240. auto state RepSetup
  241. {
  242. Begin:
  243.     CurrentJob = "RepSetup";
  244.     sleep(1.0);
  245.     if( NetConnection(StatObject.PlayerOwner.Player)==None ) {
  246.         // standalone or server listener
  247.         bReceivedURL = true;
  248.         InitDLCCheck();
  249.         ClientAllReceived();
  250.         CurrentJob = "Solo or Listen Server ";
  251.         GoToState('UpdatePerkProgress');
  252.     }
  253. }
  254.  
  255. // Sending replication data for the first time.
  256. // No ACK checks here - clients should request missing data later.
  257. state InitialReplication
  258. {
  259.     ignores ServerRequestCategories, ServerRequestWeapons, ServerRequestChars;
  260.    
  261. Begin:
  262.     CurrentJob = "InitialReplication";
  263.     if( Level.NetMode==NM_Client || NetConnection(StatObject.PlayerOwner.Player)==None )
  264.         Stop;
  265.  
  266.     NetUpdateFrequency = 5.0;
  267.     ClientReceiveURL(ServerWebSite,StatObject.PlayerOwner.GetPlayerIDHash());
  268.    
  269.     CurrentJob = "Sending Categories";
  270.     for( SendIndex=0; SendIndex<ShopCategories.Length; ++SendIndex ) {
  271.         ClientReceiveCategory(SendIndex, ShopCategories[SendIndex]);
  272.         Sleep(0.1);
  273.     }    
  274.    
  275.     CurrentJob = "Sending Weapons";
  276.     for( SendIndex=0; SendIndex<ShopInventory.Length; ++SendIndex ) {
  277.         ClientReceiveWeapon(SendIndex, ShopInventory[SendIndex].PC, ShopInventory[SendIndex].CatNum);
  278.         Sleep(0.1);
  279.     }
  280.     CurrentJob = "Sending Characters";
  281.     for( SendIndex=0; SendIndex<CustomChars.Length; ++SendIndex ) {
  282.         ClientReceiveChar(CustomChars[SendIndex],SendIndex);
  283.         Sleep(0.15);
  284.     }    
  285.    
  286.     GoToState('WaitingForACK');
  287. }
  288.  
  289. // server is waiting for client's acknowledgement that all data is
  290. state WaitingForACK
  291. {
  292. Begin:
  293.     CurrentJob = "Waiting for Weapon ACK";
  294.     SendIndex = 0;
  295.     while ( ClientAccknowledged[0]<ShopInventory.Length || ClientAccknowledged[1]<ShopCategories.Length ) {
  296.         if ( ++SendIndex == 5 ) {
  297.             ClientSendAcknowledge();  
  298.             SendIndex = 0;
  299.         }
  300.         sleep(1.0);
  301.     }
  302.     CurrentJob = "Waiting for Character ACK";
  303.     while ( ClientAckSkinNum < CustomChars.length ) {
  304.         if ( ++SendIndex == 5 ) {
  305.             ClientSendAcknowledge();  
  306.             SendIndex = 0;
  307.         }
  308.         sleep(1.0);
  309.     }    
  310.  
  311.     bRepCompleted = true;
  312.    
  313.     CurrentJob = "Sending Smiles";
  314.     for( SendIndex=0; SendIndex<SmileyTags.Length; ++SendIndex )
  315.     {
  316.         ClientReceiveTag(SmileyTags[SendIndex].SmileyTex,SmileyTags[SendIndex].SmileyTag,SmileyTags[SendIndex].bInCAPS);
  317.         Sleep(0.1f);
  318.     }
  319.     SmileyTags.Length = 0;  
  320.  
  321.     NetUpdateFrequency = 1.0;    
  322.        
  323.     CurrentJob = "ALL OK";
  324.     GotoState('UpdatePerkProgress');
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement