void Scoreboard_AddWarlock(int _iSlotID, string _Name, int _iKills, int _iDeaths, int _iScore) { if (mPlayers.ContainsKey(_iSlotID)) { Debug.LogError("Attempted to add player " + _iSlotID + ", but they already exist!"); return; } // Add new player. mPlayers.Add(_iSlotID, new ScoreboardVarStruct(_Name, _iKills, _iDeaths, _iScore)); }
//private static HttpSessionState session { get { return HttpContext.Current.Session; } } public static void CheckXSRF(Page page, HiddenField antiforgery) { string antiforgeryToken = string.Empty; antiforgeryToken = GenerateCustomizedCSRFToken(); System.Collections.Generic.SortedDictionary <string, string> l_CSRFTokenCollection = new System.Collections.Generic.SortedDictionary <string, string>(); if (!page.IsPostBack) { if (l_CSRFTokenCollection.ContainsKey(page.AppRelativeVirtualPath.ToUpper())) { l_CSRFTokenCollection.Remove(page.AppRelativeVirtualPath.ToUpper()); } l_CSRFTokenCollection.Add(page.AppRelativeVirtualPath.ToUpper(), antiforgeryToken); page.Session.Add("CSRFTokens", l_CSRFTokenCollection); antiforgery.Value = antiforgeryToken; antiforgeryToken = string.Empty; } else { if (page.Session["CSRFTokens"] == null) { throw new HttpException("Validation of Anti-XSRF token failed."); } l_CSRFTokenCollection = (System.Collections.Generic.SortedDictionary <string, string>)page.Session["CSRFTokens"]; if (!l_CSRFTokenCollection.ContainsKey(page.AppRelativeVirtualPath.ToUpper())) { throw new HttpException("Validation of Anti-XSRF token failed."); } if ((antiforgery.Value != l_CSRFTokenCollection[page.AppRelativeVirtualPath.ToUpper()])) { throw new HttpException("Validation of Anti-XSRF token failed."); } //l_CSRFTokenCollection.Remove(page.AppRelativeVirtualPath); //l_CSRFTokenCollection.Add(page.AppRelativeVirtualPath, antiforgeryToken); //page.Session.Add("CSRFTokens", l_CSRFTokenCollection); //antiforgery.Value = antiforgeryToken; } }
/// <summary> /// Returns time when attribute was last time read. /// </summary>- /// <param name="attributeIndex">Attribute index.</param> /// <returns>Is attribute read only.</returns> public DateTime GetLastReadTime(int attributeIndex) { if (!ReadTimes.ContainsKey(attributeIndex)) { return(DateTime.MinValue); } return(ReadTimes[attributeIndex]); }
internal static bool ContainKeys(Type type) { if (type == null) { return(false); } return(Cache.ContainsKey(type.GUID)); }
public bool GetDirty(int attributeIndex, out object value) { if (DirtyAttributes.ContainsKey(attributeIndex)) { value = DirtyAttributes[attributeIndex]; return(true); } value = null; return(false); }
/// <summary> /// Ajoute un contrat à la collection /// </summary> /// <param name="unContrat"></param> public void AjouterContrat(MContrat unContrat) { if (Contrats.ContainsKey(unContrat.NumeroContrat)) { throw new Exception("Le numero de contrat existe deja ou il est de valeur 0"); } else { Contrats.Add(unContrat.NumeroContrat, unContrat); } }
public static int LargestUniqueNumber(int[] A) { try { int ret = -1; ArrayList dummy = new ArrayList(); var m = new System.Collections.Generic.SortedDictionary <int, int>(); //taking a sorted dict Array.Sort(A); int n = A.Length; int[] arr = new int[A.Length]; for (int i = 0; i < n; i++) { if (!m.ContainsKey(A[i])) { m.Add(A[i], i); //adding char of string in key and index to value in dict } else { dummy.Add(A[i]);//if any repeated element hits it will be added to dummy lit } } foreach (int d in dummy) // for each repeated element in dummy loop remove the corresponding element from dict { if (m.ContainsKey(d)) { m.Remove(d); } } ret = m.Keys.Last();//returns the max i.e last key as it is sorted dict return(ret); } catch { return(-1); } }
public void AddState(IState <T> state) { if (stateDict_.ContainsKey(state.Name)) { // Debug.Assert(false, "state with nam \"" + state.Name + "\"already exist."); } stateDict_[state.Name] = state; state.Manager = this; if (inited_) { state.OnInit(); } }
/// <summary> /// /// </summary> /// <param name="macAddress">shall be in hex format. For example "00:F3:A1:01:23:45"</param> /// <returns></returns> public string GetMacVendor(string macAddress) { string macKey = macAddress.Substring(0, 2) + ":" + macAddress.Substring(3, 2) + ":" + macAddress.Substring(6, 2); if (macPrefixDictionary.ContainsKey(macKey)) { return(macPrefixDictionary[macKey]); } else if (macFullDictionary.ContainsKey(macAddress)) { return(macFullDictionary[macAddress]); } else { return("Unknown"); } }
/// <summary> /// Reads a fingerprint file wit NIC MAC addresses. The file shall be formatted according to Ettercap /// </summary> /// <param name="macFingerprintFilename">for example "etter.finger.mac"</param> private MacCollection(string macFingerprintFilename, MacFingerprintFileFormat format) { //System.IO.File.OpenRead(macFingerprintFilename) //Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) //Environment.CurrentDirectory; System.IO.FileStream fileStream = new FileStream(macFingerprintFilename, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fileStream); macPrefixDictionary = new SortedDictionary <string, string>(); macFullDictionary = new SortedDictionary <string, string>(); macFullDictionary.Add("FF:FF:FF:FF:FF:FF", "Broadcast"); while (!reader.EndOfStream) { string line = reader.ReadLine(); //see if it is an empty or commented line if (line.Length > 0 && line[0] != '#') { string macKey = null; string vendor = null; if (format == MacFingerprintFileFormat.Ettercap && line.Length > 10) { macKey = line.Substring(0, 8);//for example 00:00:01 vendor = line.Substring(10); } else if (format == MacFingerprintFileFormat.Nmap && line.Length > 7) { macKey = line.Substring(0, 2) + ":" + line.Substring(2, 2) + ":" + line.Substring(4, 2); vendor = line.Substring(7); } else if (format == MacFingerprintFileFormat.IEEE_OUI && line.Length > 15 && line.Contains("(hex)") && line.TrimStart(WHITESPACE)[2] == '-') { line = line.TrimStart(WHITESPACE); macKey = line.Substring(0, 8).Replace('-', ':'); vendor = line.Substring(line.LastIndexOf('\t') + 1); } if (macKey != null && vendor != null && !macPrefixDictionary.ContainsKey(macKey)) { macPrefixDictionary.Add(macKey, vendor); } //hashTable.Add(mac, vendor); } } }
static void Main(string[] args) { Dictionary <string, Contest> contestAndPass = new Dictionary <string, Contest>(); string command = Console.ReadLine(); while (command != "end of contests") { string name = command.Split(":")[0]; string password = command.Split(":")[1]; if (contestAndPass.ContainsKey(name) == false) { Contest contest = new Contest(name, password); contestAndPass.Add(name, contest); } command = Console.ReadLine(); } SortedDictionary <string, User> usersAndContests = new System.Collections.Generic.SortedDictionary <string, User>(); string commandTwo = Console.ReadLine(); while (commandTwo != "end of submissions") { string nameOfContest = commandTwo.Split("=>")[0]; string password = commandTwo.Split("=>")[1]; if (contestAndPass.ContainsKey(nameOfContest) && contestAndPass[nameOfContest].Password == password) { string username = commandTwo.Split("=>")[2]; int points = int.Parse(commandTwo.Split("=>")[3]); if (usersAndContests.ContainsKey(username)) { if (usersAndContests[username].Contests.ContainsKey(nameOfContest)) { if (points > usersAndContests[username].Contests[nameOfContest]) { usersAndContests[username].Contests[nameOfContest] = points; } } else { usersAndContests[username].Contests.Add(nameOfContest, points); } } else { User user = new User(username, points, nameOfContest); usersAndContests.Add(username, user); } } commandTwo = Console.ReadLine(); } string bestUser = User.BestUser(usersAndContests); Console.WriteLine($"Best candidate is {bestUser} with total {usersAndContests[bestUser].Contests.Values.Sum()} points."); Console.WriteLine("Ranking:"); foreach (var user in usersAndContests) { Console.WriteLine(user.Key); foreach (var item in user.Value.Contests.OrderByDescending(p => p.Value)) { Console.WriteLine($"# {item.Key} -> {item.Value}"); } } }
public byte[] CommitTransaction(SortedSet<BaseDataObjectVersion> objects) { Log.WriteLine ("Database.CommitTransaction()"); int oc = objects.Count; objects.RemoveWhere (obj => obj.ChunkID != null); Log.WriteLine ("Ommitting {0} objects in commit", oc - objects.Count); System.IO.MemoryStream MS = new System.IO.MemoryStream (); System.IO.MemoryStream MSRP = new System.IO.MemoryStream (); System.IO.BinaryWriter MSBW = new System.IO.BinaryWriter (MS); SortedSet<byte[]> dependencies = new SortedSet<byte[]> (BD2.Core.ByteSequenceComparer.Shared); ChunkHeaderv1 ch = new ChunkHeaderv1 (DateTime.UtcNow, ""); MSBW.Write (ch.Version); byte[] chbytes = ch.Serialize (); MSBW.Write (chbytes.Length); MSBW.Write (chbytes); MSBW.Write (1);//section count Log.WriteLine ("{0} sections", 1); int n = 0; //foreach (var tup in data) { MSBW.Write (1); Log.WriteLine ("Section version is {0}", 1); System.Collections.Generic.SortedDictionary <BaseDataObjectVersion, LinkedListNode<BaseDataObjectVersion>> ss = new System.Collections.Generic.SortedDictionary <BaseDataObjectVersion, LinkedListNode<BaseDataObjectVersion>> (); System.Collections.Generic.LinkedList <BaseDataObjectVersion> ll = new LinkedList<BaseDataObjectVersion> (); foreach (BaseDataObjectVersion bdo in objects) { if (!ss.ContainsKey (bdo)) ss.Add (bdo, ll.AddLast (bdo)); foreach (BaseDataObjectVersion dependency in bdo.GetDependenies ()) { byte[] dep = dependency.ChunkID; if (dep == null) { if (ss.ContainsKey (bdo)) { } else { ss.Add (dependency, ll.AddBefore (ss [bdo], dependency)); } } else { if (!dependencies.Contains (dependency.ChunkID)) dependencies.Add (dependency.ChunkID); } } } foreach (BaseDataObjectVersion bdo in ll) { n++; System.IO.MemoryStream MST = new System.IO.MemoryStream (); MST.Write (bdo.ObjectType.ToByteArray (), 0, 16); bdo.Serialize (MST, encryptedStorageManager); byte[] bytes = MST.ToArray (); Log.WriteLine ("object type+bytes: {0}", bytes.ToHexadecimal ()); //Log.WriteLine ("Object of type {0} serialized to {1} bytes.", bdo.GetType ().FullName, bytes.Length); { System.IO.MemoryStream MSC = new System.IO.MemoryStream (); System.IO.BinaryWriter BWC = new System.IO.BinaryWriter (MSC); BWC.Write (bytes.Length); MSRP.Write (MSC.ToArray (), 0, 4); } MSRP.Write (bytes, 0, bytes.Length); } byte[] encoded = MSRP.ToArray (); Log.WriteLine ("{0} objects encoded in {1} bytes", objects.Count, encoded.Length); MSBW.Write (n); MSBW.Write (encoded.Length); MSBW.Write (encoded); Log.WriteLine ("encoded:{0}", encoded.ToHexadecimal ()); //} if (n == 0) { Log.WriteLine ("No objects to save, nothing to do"); return null; } System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create (); Log.WriteLine ("{0} dependencies", dependencies.Count); byte[][] deps = new byte [dependencies.Count][]; int depid = 0; foreach (byte[] dep in dependencies) deps [depid++] = dep; Log.WriteLine ("Writing {0} bytes representing {1} objects to backend", MS.Length, n); byte[] buf = MS.ToArray (); byte[] chunkID = sha.ComputeHash (buf); foreach (var ds in dataStorage) Log.WriteLine ("We have: {0}", ds.Key.ToHexadecimal ()); byte[] cus = userStorage.GetCommonStorage (); Log.WriteLine ("Common storage id is {0}", cus.ToHexadecimal ()); if (!dataStorage.ContainsKey (cus)) { Log.WriteLine ("and we don't have it."); Log.WriteLine ("we only have:"); foreach (var t in dataStorage) Log.WriteLine (" ID: {0}", t.Key.ToHexadecimal ()); } dataStorage [cus].Push (chunkID, buf, deps, userStorage.Sign (chunkID)); foreach (var bdo in objects) { bdo.SetChunkID (chunkID); } Log.WriteLine ("Chunk saved with ID:{0}", chunkID.ToHexadecimal ()); return chunkID; }
public byte[] CommitTransaction(SortedSet <BaseDataObjectVersion> objects) { System.IO.MemoryStream MS = new System.IO.MemoryStream(); System.IO.MemoryStream MSRP = new System.IO.MemoryStream(); System.IO.BinaryWriter MSBW = new System.IO.BinaryWriter(MS); SortedSet <byte[]> dependencies = new SortedSet <byte[]> (BD2.Core.ByteSequenceComparer.Shared); ChunkHeaderv1 ch = new ChunkHeaderv1(DateTime.UtcNow, ""); MSBW.Write(ch.Version); byte[] chbytes = ch.Serialize(); MSBW.Write(chbytes.Length); MSBW.Write(chbytes); MSBW.Write(1); Console.WriteLine("{0} sections", 1); int n = 0; //foreach (var tup in data) { MSBW.Write(1); Console.WriteLine("Section version is {0}", 1); System.Collections.Generic.SortedDictionary <BaseDataObjectVersion, LinkedListNode <BaseDataObjectVersion> > ss = new System.Collections.Generic.SortedDictionary <BaseDataObjectVersion, LinkedListNode <BaseDataObjectVersion> > (); System.Collections.Generic.LinkedList <BaseDataObjectVersion> ll = new LinkedList <BaseDataObjectVersion> (); foreach (BaseDataObjectVersion bdo in objects) { if (!ss.ContainsKey(bdo)) { ss.Add(bdo, ll.AddLast(bdo)); } foreach (BaseDataObjectVersion dependency in bdo.GetDependenies()) { byte[] dep = dependency.ChunkID; if (dep == null) { if (ss.ContainsKey(bdo)) { } else { ss.Add(dependency, ll.AddBefore(ss [bdo], dependency)); } } else { if (!dependencies.Contains(dependency.ChunkID)) { dependencies.Add(dependency.ChunkID); } } } } foreach (BaseDataObjectVersion bdo in ll) { n++; System.IO.MemoryStream MST = new System.IO.MemoryStream(); MST.Write(bdo.ObjectType.ToByteArray(), 0, 16); bdo.Serialize(MST, encryptedStorageManager); byte[] bytes = MST.ToArray(); //Console.WriteLine ("Object of type {0} serialized to {1} bytes.", bdo.GetType ().FullName, bytes.Length); { System.IO.MemoryStream MSC = new System.IO.MemoryStream(); System.IO.BinaryWriter BWC = new System.IO.BinaryWriter(MSC); BWC.Write(bytes.Length); MSRP.Write(MSC.ToArray(), 0, 4); } MSRP.Write(bytes, 0, bytes.Length); } byte[] encoded = MSRP.ToArray(); Console.WriteLine("{0} objects encoded in {1} bytes", objects.Count, encoded.Length); MSBW.Write(encoded.Length); MSBW.Write(encoded); //} if (n == 0) { Console.WriteLine("No objects to save, nothing to do"); return(null); } System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create(); Console.WriteLine("{0} dependencies", dependencies.Count); byte[][] deps = new byte [dependencies.Count][]; int depid = 0; foreach (byte[] dep in dependencies) { deps [depid++] = dep; } Console.WriteLine("Writing {0} bytes representing {1} objects to backend", MS.Length, n); byte[] buf = MS.ToArray(); byte[] chunkID = sha.ComputeHash(buf); dataStorage [DefaultStorage].Push(chunkID, buf, deps, userStorage.Sign(chunkID)); foreach (var bdo in objects) { bdo.SetChunkID(chunkID); } return(chunkID); }