private void loadClaimlist() { string filepath = Path.Combine(path, claimantFile); if (!File.Exists(filepath)) { return; } claimMap.Clear(); byte[] read = File.ReadAllBytes(filepath); BinReader reader = new BinReader(read); int claimantCount = reader.readInt(); for (int i = 0; i < claimantCount; i++) { string name = reader.readUTF8String(); claimMap.Add(name, new List <KeyGamePair>()); int len = reader.readInt(); for (int j = 0; j < len; j++) { KeyGamePair kgp = new KeyGamePair(); kgp.deserialize(reader); claimMap[name].Add(kgp); } } }
private string claimGameKey(int idx, ulong id, string user) { string ret = "Invalid index!"; int i = idx - 1; if (i < 0 || i >= games.Count) { return(ret); } if (games[i].Count < 2) { ret = "There are no more keys left for the game \"" + games[i][0] + "\""; } else { int end = games[i].Count - 1; string key = games[i][end]; games[i].RemoveAt(end); ret = "Here is a key for the game \"" + games[i][0] + "\": ```" + key + "```"; userTimeCD.Add(id, CLAIM_CD); //Add user on cooldown upon successful redemption of key. if (!claimMap.ContainsKey(user)) { List <KeyGamePair> kgp = new List <KeyGamePair>(); KeyGamePair pair = new KeyGamePair(); pair.game = games[i][0]; pair.key = key; kgp.Add(pair); claimMap.Add(user, kgp); } else { KeyGamePair pair = new KeyGamePair(); pair.game = games[i][0]; pair.key = key; claimMap[user].Add(pair); } saveClaimlist(); saveKeylist(); } return(ret); }