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 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 |
/****************************************************************************** UTAN Ban Manager v1.04 <br /> Coded by Wormbo, Copyright © 2003-2006 UTAN, 2009-2011 Wormbo <br /> <br /> Stores the UTAN bans affecting this server. ******************************************************************************/ class UTANBanDatabase extends Object dependson(MutUTAN); //============================================================================= // Structs //============================================================================= /** Compressed ban data. */ /* Why is this a struct of two rotators? Well, rotators are serialized extremely efficiently and only require exactly 3 * 4 = 12 bytes, plus the overhead for two struct members. Ban data consists of a ban ID (relatively small positive int), an IP in CIDR notation (can also be expressed as 32 bit for the IP part and 5 bits for the CIDR prefix), a GUID (128 bit = 4 ints) and several boolean flags. (1 bit each) The ban ID is stored in A.Pitch. Because the ID is always positive and usually quite small, the most significant bits of A.Pitch are used for the CIDR prefix and the various flags. The IP is stored in A.Yaw. A.Roll, B.Pitch, B.Yaw and B.Roll provide the space for the 4 ints of the GUID. See the GetEntry() and AddEntry() functions for storage details of the ban ID, flags and CIDR prefix. */ struct TBanData { var rotator A, B; }; /** A ban reason. These are stores separately, if present. */ struct TBanReason { var config int ID; var config string Reason; }; //============================================================================= // Variables //============================================================================= /** The actual ban list data. Bans can consist of more than one entry here, identified by the same ban ID value. Additionally, ban excludes also reside in this list, indicated by the exclude flag in bit 23 of A.Pitch. */ var array<TBanData> BanList; /** Last remote update time as seconds since epoch. Sent when communicating with the configured masterserver. */ var config int LastUpdate; /** Ban reasons. */ var config array<TBanReason> BanReasons; var transient array<int> SortedReasons; function Init() { local int i, Low, Middle, High; if (BanReasons.Length > 0) { SortedReasons[i++] = 0; if (BanReasons.Length > 1) { do { Low = 0; High = SortedReasons.Length; do { Middle = (High + Low) / 2; if (BanReasons[SortedReasons[Middle]].ID < BanReasons[i].ID) Low = Middle + 1; else High = Middle; } until (Low >= High); SortedReasons.Insert(Low, 1); SortedReasons[Low] = i; } until (++i == BanReasons.Length); } } } function int GetNumEntries() { return BanList.Length; } function ClearEntries() { BanList.Length = 0; BanReasons.Length = 0; SortedReasons.Length = 0; } function MutUTAN.TListEntry GetEntry(int Index) { local MutUTAN.TListEntry Result; Result.ID = BanList[Index].A.Pitch & 0x007FFFFF; Result.bIsExclude = bool(BanList[Index].A.Pitch & 0x00800000); Result.bIsRemote = bool(BanList[Index].A.Pitch & 0x80000000); Result.bIsCheater = bool(BanList[Index].A.Pitch & 0x40000000); Result.bIsDisabled = bool(BanList[Index].A.Pitch & 0x20000000); Result.IP.Prefix = BanList[Index].A.Pitch >> 24 & 0x1F; Result.IP.IP = BanList[Index].A.Yaw & -1 << -Result.IP.Prefix; Result.GUID.A = BanList[Index].A.Roll; Result.GUID.B = BanList[Index].B.Pitch; Result.GUID.C = BanList[Index].B.Yaw; Result.GUID.D = BanList[Index].B.Roll; return Result; } function int AddEntry(MutUTAN.TListEntry ListEntry) { local int i; i = BanList.Length; BanList.Length = i + 1; BanList[i].A.Pitch = ListEntry.ID & 0x007FFFFF | int(ListEntry.bIsExclude) << 23 | ListEntry.IP.Prefix << 24 | int(ListEntry.bIsDisabled) << 29 | int(ListEntry.bIsCheater) << 30 | int(ListEntry.bIsRemote) << 31; BanList[i].A.Yaw = ListEntry.IP.IP; BanList[i].A.Roll = ListEntry.GUID.A; BanList[i].B.Pitch = ListEntry.GUID.B; BanList[i].B.Yaw = ListEntry.GUID.C; BanList[i].B.Roll = ListEntry.GUID.D; return i; } function bool SaveDatabase(LevelInfo Level, string BanDatabaseName) { return Level.Game.SavePackage(BanDatabaseName); } function string GetReason(int ID) { local int Low, Middle, High; High = SortedReasons.Length; while (Low < High) { Middle = (High + Low) / 2; if (BanReasons[SortedReasons[Middle]].ID < ID) Low = Middle + 1; else High = Middle; } if (Low < SortedReasons.Length && BanReasons[SortedReasons[Low]].ID == ID) return BanReasons[SortedReasons[Low]].Reason; return ""; } function SetReason(int ID, optional string Reason) { local int Low, Middle, High; local int i; High = SortedReasons.Length; while (Low < High) { Middle = (High + Low) / 2; if (BanReasons[SortedReasons[Middle]].ID < ID) Low = Middle + 1; else High = Middle; } if (Reason == "") { // delete current reason if (Low < SortedReasons.Length && BanReasons[SortedReasons[Low]].ID == ID) { for (i = 0; i < SortedReasons.Length; i++) { if (SortedReasons[i] > SortedReasons[Low]) SortedReasons[i]--; } BanReasons.Remove(SortedReasons[Low], 1); SortedReasons.Remove(Low, 1); } } else if (Low < SortedReasons.Length && BanReasons[SortedReasons[Low]].ID == ID) { // update reason BanReasons[SortedReasons[Low]].Reason = Reason; } else { // add new reason i = BanReasons.Length; BanReasons.Length = i + 1; BanReasons[i].ID = ID; BanReasons[i].Reason = Reason; SortedReasons.Insert(Low, 1); SortedReasons[Low] = i; } } //============================================================================= // Default values //============================================================================= defaultproperties { } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |