protected override void DataOperation(GStatsSession session, Dictionary <string, string> recv) { //search database for user's password //We do not store user's plaintext password, so we can not check this response switch (_authMethod) { case AuthMethod.PartnerIDAuth: FindProfileByAuthtoken(recv); break; case AuthMethod.ProfileIDAuth: //even if we do not check response challenge //we have to check the pid is in our databse FindProfileByProfileid(recv); break; case AuthMethod.CDkeyAuth: FrindProfileByCDKeyHash(recv); break; default: _errorCode = GstatsErrorCode.Database; break; } }
public virtual void Handle(GStatsSession session, Dictionary <string, string> recv) { LogWriter.LogCurrentClass(this); CheckRequest(session, recv); if (_errorCode != GstatsErrorCode.NoError) { LogWriter.ToLog(LogEventLevel.Error, ErrorMessage.ToMsg(_errorCode)); return; } DataOperation(session, recv); if (_errorCode == GstatsErrorCode.Database) { LogWriter.ToLog(LogEventLevel.Error, ErrorMessage.ToMsg(_errorCode)); return; } ConstructResponse(session, recv); if (_errorCode != GstatsErrorCode.NoError) { LogWriter.ToLog(LogEventLevel.Error, ErrorMessage.ToMsg(_errorCode)); return; } Response(session, recv); }
protected override void DataOperation(GStatsSession session, Dictionary <string, string> recv) { using (var db = new retrospyContext()) { var result = from p in db.Pstorage where p.Profileid == _profileid && p.Dindex == _dindex && p.Ptype == _ptype select p; Pstorage ps; if (result.Count() == 0) { //insert a new record in database ps = new Pstorage(); ps.Dindex = _dindex; ps.Profileid = _profileid; ps.Ptype = _ptype; ps.Data = _keyValueStr; db.Pstorage.Add(ps); } else if (result.Count() == 1) { //update an existed record in database ps = result.First(); ps.Data = _keyValueStr; } db.SaveChanges(); } }
protected override void CheckRequest(GStatsSession session, Dictionary <string, string> recv) { base.CheckRequest(session, recv); if (recv.ContainsKey("pid") && recv.ContainsKey("resp")) { //we parse profileid here if (!uint.TryParse(recv["pid"], out _profileid)) { _errorCode = GstatsErrorCode.Parse; } _authMethod = AuthMethod.ProfileIDAuth; } else if (recv.ContainsKey("authtoken") && recv.ContainsKey("response")) { _authMethod = AuthMethod.PartnerIDAuth; } else if (recv.ContainsKey("keyhash") && recv.ContainsKey("nick")) { _authMethod = AuthMethod.CDkeyAuth; } else { _errorCode = GstatsErrorCode.Parse; } }
protected override void CheckRequest(GStatsSession session, Dictionary <string, string> recv) { base.CheckRequest(session, recv); if (!recv.ContainsKey("nick") || !recv.ContainsKey("keyhash")) { _errorCode = GstatsErrorCode.Parse; return; } }
protected virtual void Response(GStatsSession session, Dictionary <string, string> recv) { if (_sendingBuffer == null) { return; } session.SendAsync(_sendingBuffer); }
protected override void DataOperation(GStatsSession session, Dictionary <string, string> recv) { //we have to verify the challenge response from the game, the response challenge is computed as //len = sprintf(resp, "%d%s",g_crc32(challenge,(int)strlen(challenge)), gcd_secret_key); //MD5Digest((unsigned char *)resp, (unsigned int)len, md5val); //DOXCODE(respformat, sizeof(respformat) - 1, enc3); //len = sprintf(resp, respformat, gcd_gamename, md5val, gameport); // for now we do not check this session.PlayerData.SessionKey = (uint)new System.Random().Next(0, 2147483647); }
public void Switch(GStatsSession session, string message) { try { if (message[0] != '\\') { return; } string[] recieved = message.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertRequestToKeyValue(recieved); switch (recv.Keys.First()) { case "auth": new AuthHandler().Handle(session, recv); break; case "authp": new AuthPHandler().Handle(session, recv); break; case "getpid": new GetPidHandler().Handle(session, recv); break; case "getpd": //get player data new GetPDHandler().Handle(session, recv); break; case "setpd": new SetPDHandler().Handle(session, recv); break; case "updgame": new UpdGameHandler().Handle(session, recv); break; case "newgame": new NewGameHandler().Handle(session, recv); break; default: LogWriter.UnknownDataRecieved(message); break; } } catch (Exception e) { LogWriter.ToLog(e); } }
protected override void DataOperation(GStatsSession session, Dictionary <string, string> recv) { base.DataOperation(session, recv); using (var db = new retrospyContext()) { var result = from p in db.Profiles join s in db.Subprofiles on p.Profileid equals s.Profileid where s.Cdkeyenc == recv["cdkeyhash"] && p.Nick == recv["nick"] select s.Profileid; if (result.Count() != 1) { _errorCode = GstatsErrorCode.Database; return; } _protileid = result.First(); } }
protected override void CheckRequest(GStatsSession session, Dictionary <string, string> recv) { base.CheckRequest(session, recv); if (recv.ContainsKey("pid")) { if (!uint.TryParse(recv["pid"], out _profileid)) { _errorCode = GstatsErrorCode.Parse; return; } } else { _errorCode = GstatsErrorCode.Parse; return; } if (recv.ContainsKey("ptype")) { if (!uint.TryParse(recv["ptype"], out _persistantStorageType)) { _errorCode = GstatsErrorCode.Parse; return; } } else { _errorCode = GstatsErrorCode.Parse; return; } if (recv.ContainsKey("dindex")) { if (!uint.TryParse(recv["dindex"], out _dataIndex)) { _errorCode = GstatsErrorCode.Parse; return; } } else { _errorCode = GstatsErrorCode.Parse; return; } }
protected virtual void CheckRequest(GStatsSession session, Dictionary <string, string> recv) { if (recv.ContainsKey("lid")) { if (!uint.TryParse(recv["lid"], out _localId)) { _errorCode = GstatsErrorCode.Parse; } } //worms 3d use id not lid so we added an condition here if (recv.ContainsKey("id")) { if (!uint.TryParse(recv["id"], out _localId)) { _errorCode = GstatsErrorCode.Parse; } } }
protected override void DataOperation(GStatsSession session, Dictionary <string, string> recv) { base.DataOperation(session, recv); //search player data in database; //using (var db = new retrospyContext()) //{ // var result = from ps in db.Pstorage // where ps.Ptype == _persistantStorageType // && ps.Dindex == _dataIndex // && ps.Profileid == _profileid // select ps.Data; // if (result.Count() != 1) // { // _errorCode = GstatsErrorCode.Database; // return; // } // //TODO figure out what is the function of keys in request // //throw new NotImplementedException(); //} }
protected override void CheckRequest(GStatsSession session, Dictionary <string, string> recv) { base.CheckRequest(session, recv); if (!uint.TryParse(recv["pid"], out _profileid)) { _errorCode = GstatsErrorCode.Parse; return; } if (!uint.TryParse(recv["ptype"], out _ptype)) { _errorCode = GstatsErrorCode.Parse; return; } if (!uint.TryParse(recv["dindex"], out _dindex)) { _errorCode = GstatsErrorCode.Parse; return; } if (!uint.TryParse(recv["length"], out _length)) { _errorCode = GstatsErrorCode.Parse; return; } //we extract the key value data foreach (var d in recv.Skip(5)) { if (d.Key.ToString() == "lid") { break; } _keyValueStr += @"\" + d.Key + @"\" + d.Value; } }
protected override void ConstructResponse(GStatsSession session, Dictionary <string, string> recv) { _sendingBuffer = string.Format(@"\sesskey\{0}", session.PlayerData.SessionKey); }
protected override void ConstructResponse(GStatsSession session, Dictionary <string, string> recv) { _sendingBuffer = $@"\getpidr\{_protileid}\lid\{_localId}"; }
protected override void ConstructResponse(GStatsSession session, Dictionary <string, string> recv) { _sendingBuffer = $@"\getpdr\1\pid\{recv["pid"]}\lid\{_localId}\mod\1234\length\5\data\mydata"; }
protected override void ConstructResponse(GStatsSession session, Dictionary <string, string> recv) { //we did not store the plaintext of user password so we do not need to check this _sendingBuffer = $@"\pauthr\{_profileid}\lid\{_localId}\"; }
protected virtual void ConstructResponse(GStatsSession session, Dictionary <string, string> recv) { }
protected virtual void DataOperation(GStatsSession session, Dictionary <string, string> recv) { }