Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 |
class KFSteamWebApi extends Actor; var String getRequestLeft; var String getRequestRight; var String getRequestSteamID; var String getResponse; var String steamAPIAddr; var int myRetryCount; var int myRetryMax; var int appID; var string steamID; var ROBufferedTCPLink myLink; var string LinkClassName; var bool sendGet; var bool pageWait; var string playerStats; simulated delegate AchievementReport( bool HasAchievement, string Achievement, int gameID, string steamID); protected function ROBufferedTCPLink CreateNewLink() { local class<ROBufferedTCPLink> NewLinkClass; local ROBufferedTCPLink NewLink; if ( LinkClassName != "" ) { NewLinkClass = class<ROBufferedTCPLink>(DynamicLoadObject( LinkClassName, class'Class')); } if ( NewLinkClass != None ) { NewLink = Spawn( NewLinkClass ); } NewLink.ResetBuffer(); return NewLink; } function GetAchievements(string steamIDIn) { steamID = steamIDIn; playerStats = ""; if(myLink == None) { myLink = CreateNewLink(); } if(myLink != None) { myLink.ServerIpAddr.Port = 0; sendGet = true; myLink.Resolve(steamAPIAddr); // NOTE: This is a non-blocking operation SetTimer(0.25, true); } else { // myMOTD = myMOTD$"|| myLink is None"; } } event Timer() { local string text; local string command; local int count; if(myLink != None) { if ( myLink.ServerIpAddr.Port != 0) { if(myLink.IsConnected()) { if(sendGet) { command = getRequestLeft$appid$getRequestSteamID$steamID$getRequestRight$myLink.CRLF$"Host: "$steamAPIAddr$myLink.CRLF$myLink.CRLF; myLink.SendCommand(command); pageWait = true; myLink.WaitForCount(1,20,1); // 20 sec timeout sendGet = false; } else { if(pageWait) { //log("waiting"); } } } else { if(sendGet) { log("could not connect"); } } } else { if (myRetryCount++ > myRetryMax) { log("too many retries!"); } } if(myLink.PeekChar() != 0) { pageWait = false; // data waiting //these two while statements get all the data we need. while(myLink.ReadBufferedLine(text)) { playerStats = playerStats$text; } while(count > 0 ) { count = myLink.ReadText(text); playerStats = playerStats$text; } count = InStr(playerStats, "\"success\": true" ); if(count == -1 ) { log("webapi*********** still need to wait", 'DevNet'); SetTimer(0.250000, true); return; } else { log("webapi EOF reached", 'DevNet'); } log(playerStats, 'DevNet'); log("webapi********playerstats", 'DevNet'); HasAchievement("NotAWarhammer"); myLink.DestroyLink(); myLink = none; return; } } SetTimer(0.250000, true); } function bool HasAchievement(string achievement) { local int position; local string rhs; local string findString; findString = "\"apiname\": \""$achievement$"\","; position = InStr(playerStats, findString ); //we found it! if( position != -1 ) { rhs = Mid(playerStats, position +Len(FindString), 20 );//- Len(findString) ); position = InStr(rhs,"achieved\": 1"); } AchievementReport( position != -1, achievement, appID, steamID); if( position != -1 ) { return true; } return false; } defaultproperties { getRequestLeft="GET /ISteamUserStats/GetPlayerAchievements/v0001/?appid=" getRequestRight="&key=6477773857A981BC6F4F50D7CAFD59E4&format=json HTTP/1.1" getRequestSteamID="&steamID=" steamAPIAddr="api.steampowered.com" myRetryMax=40 AppID=213650 LinkClassName="ROInterface.ROBufferedTCPLink" sendGet=True bHidden=True } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |