テーブル (Lua) にコンテンツを追加すると、テーブル内のすべてのコンテンツが突然消えるという大きな問題が発生します。問題のテーブルは禁止リスト (現在 608 エントリ) のデータを保持し、 table.insert を使用してテーブル内に配置されますが、ユーザーのリード エントリはUmbra.Banlist[profileId] = {};として行われます。. Umbra.Banlist [profileId] = {}; テーブルのみは、Umbra.Banlist テーブル内にコンテンツがあることを意味する必要があります。コードの実行時および使用時にエラーは発生しません
if (#Umbra.Banlist == 0) then
System.LogAlways(Umbra.Tag.." The Banlist seems to be empty. It seems that some part of loading has failed.");
end
私はこれを得る:
Webやこちらのサイトで調べましたが、関連する質問がないようですので、こちらに投稿させていただきます。
このコードは Crysis Wars のサーバー mod の一部ですが (以下の関数全体を参照)、手元に Lua ライブラリ全体があります (したがって、あなたの答えが問題を解決しないと思われる場合でも心配しないでください)。
コード:
Umbra.ReadBans = function()
self = Umbra;
System.LogAlways(Umbra.Tag.." Starting banlist read.");
FileHnd, err = io.open(Root().."Mods/Infinity/System/Read/Banlst.lua", "r");
if (not FileHnd) then
System.LogAlways(Umbra.Tag.." Unable to find file 'Banlst.lua'.");
return;
end
for line in FileHnd:lines() do
local name, profile, ip, domain, reason, date, bannedby = line:match([[Umbra.BanSystem:Add%('(.-)', '(.+)', '(.+)', '(.+)', '(.+)', '(.+)', '(.-)'%);]]);
if (not name) then
System.LogAlways(Umbra.Tag.." Failed to read the banlist at line "..count or 0);
break;
end
System.LogAlways(Umbra.Tag.." Banlist; Name: [ "..name.." ], For: [ "..reason.." ], By: [ "..bannedby.." ]");
--local Msg, Date, Reason, Type, Domain = line:match([[User:Read%( "(.-)", { Date="(.+)"; Reason="(.+)"; Typ="(.+)"; Info="(.+)"; } %);]]);
--User:Read( "Banned", { Date="31.03.2011"; Reason="WEBSTREAM"; Typ="Inetnum"; Info="COMPUTER.SED.gg"; } );
--Umbra.BanSystem:Add('patryk', '258132298', '178.183.243.163', '178.183.243.163.dsl.dynamic.t-mobile.pl', 'flyhack', '08/11/2012 | 21:39:53', 'Anti-Noob');
Umbra.Banlist[profile] = {};
table.insert(Umbra.Banlist[profile], name);
table.insert(Umbra.Banlist[profile], ip);
table.insert(Umbra.Banlist[profile], domain);
table.insert(Umbra.Banlist[profile], reason);
table.insert(Umbra.Banlist[profile], date);
table.insert(Umbra.Banlist[profile], bannedby);
--[[Umbra.Banlist[profile].name = name;
Umbra.Banlist[profile].ip = ip;
Umbra.Banlist[profile].domain = domain;
Umbra.Banlist[profile].reason = reason;
Umbra.Banlist[profile].date = date;
Umbra.Banlist[profile].bannedby = bannedby;--]]
if not count then count = 0; end
count = count + 1;
end
Umbra.Bans = {};
Umbra.Bans.cnt = count;
System.LogAlways(Umbra.Tag.." Read "..count.." banned players (added into the Umbra Global Banlist)");
if (#Umbra.Banlist == 0) then
System.LogAlways(Umbra.Tag.." The Banlist seems to be empty. It seems that some part of loading has failed.");
end
count = nil; --Purge this one as well, again!
end
編集:
プロファイルがテーブルに存在しない場合、以下のコードを出力する必要があるというメッセージが表示されないため、プロファイルは実際に存在します。
if (not Umbra.Banlist[profile]) then
System.LogAlways(Umbra.Tag.." Error in 'Umbra.Banlist': The profile does not exist.)");
break;
end
別の編集:
システムが実際に「ID」変数を取得できることの証明: