How can I check if my "variable" is a valid "ID" - api

API: https://github.com/satom99/litcord
How can I check my valiable if its a valid ID?
local cmd, serverID, channelID, arg = string.match(message.content, '(%S+) (%d+) (%d+) (%S+.*)')
local server = client.servers:get('id', serverID)
serverID is the variable and I need to check if the serverID is a valid ID
Otherwise I will get an error that server is a nil value.
I am trying days to finish one command and this is a part of it.
If you need more contents then please tell me, I will link it to you.
Full Code:
client:on(
'message',
function(message)
local userID = message.author.id
local cmd, serverID, channelID, arg = string.match(message.content, '(%S+) (%d+) (%d+) (%S+.*)')
local server = client.servers:get('id', serverID)
local channel = server.channels:get('id', channelID)
local cmd = cmd or message.content
if (cmd == "!say") and message.parent.is_private then
if (userID == "187590758360940545") then
if not server then
return
end
if (server == servers) then
if (channel == channels) then
message.channel:sendMessage(arg)
else
message:reply("I don't know this channel.")
return
end
message:reply("I don't know this server.")
end
else
message:reply(":sob: Stop!!!!")
end
end
end
)
And how I can let it write in the channel I want with functions
message.channel:sendMessage(arg)
this is like message:reply
it replies back where the message came from.

Let's forget about validating the serverID for one moment.
Of course you should always handle the case client.servers:get('id', serverID) returing nil.
Simply validating serverID somehow and hoping that you will get a valid server handle back is not an option.
So either use Luas error handling features https://www.lua.org/manual/5.3/manual.html#2.3
or simply check server with an if statement so you won't use server if it is nil.
Simplified:
local server = client.servers:get('id', serverID)
if not server then
print("No server with id '" .. serverID .. "' found.")
return -- or do something clever here, show a message box or whatever...
end
-- server won't be nil from here
Unless you know for sure that there is no other way for nil being returned you should handle that possibility properly.

Related

attempt to index a nil value (field 'eth0')

this is a Lua quickapp problem i install it a year ago and it was working fine but went through some problems in my system because of electricity.
This is the part I Have problem with:
function BroadlinkDeviceManager:discover(func)
local blDevices = {}
local network = api.get("/proxy?url=http://localhost:11112/api/settings/network")
local myIP = network.networkConfig.eth0.ipConfig.ip
-- for debugging
if dofile then
myIP = "192.168.1.59" -- Util.getIPaddress() --
end
The Quick app is for Broadlink RM4 when I setup it again to my wifi the QA always give me this error
[DEBUG] [QUICKAPP1613]: ./include/manager.lua:97: attempt to index a nil value (field 'eth0')
[ERROR] [QUICKAPP1613]: QuickApp crashed
[ERROR] [QUICKAPP1613]: Unknown error occurred: handleJsonRpc
I search it but i can't find any solution I also asked in forum but I got nothing.
If there is any one can help me with this.
You must verify if network.networkConfig.eth0 is not nil before indexing network.networkConfig.eth0.ipConfig.ip :
local myIP
if network.networkConfig.eth0 ~= nil then
myIP = network.networkConfig.eth0.ipConfig.ip
end
Thank you for your response, the error disappear put there was a function to check the IP of the device
local function makeDiscoverDevicesMsg()
local ipa1, ipa2,ipa3, ipa4 = myIP:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)")
then I edit to be "^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$"
I also try to make every variable with (tonumber) but all give me the same error attempt to index a nil value (upvalue 'myIP')

How do I handle session id context uninitialized in Thrift

sorry to bother you guys,
I have a Thrift server program in c++. Whenever a client connects to me, the handshake succeeds, as does the first Thrift command sent, but the second command sent fails with the error "session id context uninitialized".
The client's next command re-establishes the connection and succeeds, but the fourth will fail again with "session id context uninitialized".
The exact error is
TConnectedClient died: SSL_accept: session id context uninitialized (SSL_error_code = 1)
TConnectedClient input close failed: session id context uninitialized (SSL_error_code = 1)
TConnectedClient output close failed: session id context uninitialized (SSL_error_code = 1)
every 'even' command
My problem seems similar to THIS, but I can't seem to figure out how to change the context of my session to set the SSL_OP_NO_TICKET flag.
I tried adding a ServerEventHandler, but I don't think I can change the serverContext that is present there.
Can anyone help me?
Below is the section of main() where I declare and start the server. If more information is needed, please ask. (sorry if I typo-ed any code, I had to retype by hand it here)
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactoryT<TBufferBase>());
::apache::thrift::stdcxx::shared_ptr<My_svrHandler> handler(new My_svrHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new My_svrProcessor(handler));
::apache::thrft::stdcxx::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory(SSL::TLSv1_2));
sslSocketFactory->loadCertificate(certLocation);
sslSocketFactory->loadPrivateKey(keyLocation);
sslSocketFactory->loadTrustedCertificates(CALocation);
sslSocketFactory->authenticate(true);
::apache::thrift::stdcxx::shared_ptr<TServerSocket> serverSocket(new TSSLServerSocket(9090, sslSocketFactory));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<apache::thrift::server::Tserver> server;
::apache::thrift::stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(10);
::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory> threadFactory = ::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
server.reset(new TThreadedPoolServer(processor, serverSocket, transportFactory, protocolFactory, threadmanager));
if(server.get() != NULL)
{
apache::thrift::concurrency::PlatformThreadFactory factory;
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Thread> thread = factory.newThread(serverThreadRunner);
signal(SIGPIPE, SIG_IGN);
thread->start();
while(1){}
server->stop();
thread->join();
server.reset();
}

How to check if a "Send Query" is over?

I need to check if my res from dbSendQuery() is over.
My code is like this:
db <- dbConnect(drv=SQLite(),flags=SQLITE_RW,dbname="db.sqlite",synchronous = "off")
dbBegin(db)
res <- dbSendQuery(db,"Update Operation SET Name = 'teste' where Id = 1")
if("my SendQuery is over"){
dbClearResult(res)
dbCommit(db)
dbDisconnect(db)
}
I need to know when it is over to send this to commit and then disconnect.
UPDATE 1
Im my sistem, for this example above can happen with more than 1 users simultaneous.
Then, when the first connection in db is over, i need to finish him requisition and provide to the other connection the possibility to write your query.
dbSendQuery() always awaits completion. You can double-check by calling dbGetRowsAffected(res) .
For SQL statements that are run for the side effect and do not return a value, dbSendStatement() is preferred.
The synchronous = "off" argument to dbConnect() is a misnomer, this defines when and how the data is written to disk; no multi-threading is involved here.

How to work out how game players are cheating?

Before ask my question, I have to explain you my project and how I'm working. I make a server for a game. This server need a lot of development, 800k lines of code.
After more than one month. It appears there is a cheat some players are using to destroy player's fun.
I have to admit it's a bit hard for me to figure out how to defend myself about this. The server owners community are just under attack too much and everyone is trying to defend himself as they can.
I'm working in Lua, JSON, HTML and CSS for this project, 99% Lua.
What things the game client has control over :
The client can do commands but commands are only allowed to admin. Except if the injection of his own file make a new command. And can inject code inside the client game(explain after).
What the server does :
I guess, here is where we may can do something. All servers have tons of mods installed, so all client are downloading all my mod/client scripts to trigger my servers events.
What is the process of sending a command :
the client can use chat /command [attribut][attribut2]
the client can run the client's console and : command [attribut][attribut2]
How cheaters are doing it?
1) Injector hidden in the memory with windows executable.
2) They are loading a client file to make clients commands to call server triggers*.
(because, yes, it's poor everyone is using same scripts so it's known triggers names)
*) To do that they open a client console and writing inside : "exec c:/filename.lua" )
50% of cheat scripts are obfuscated with AHCI & variable replacement like the following.
What does a cheat look like?
I cannot post the full code here >Body is limited to 30000 characters; you entered 208906.< >obfuscated< >not indented(1 ligne)<
-A global function :
function IllIlllIllIlllIlllIlllIll(IllIlllIllIllIll) if (IllIlllIllIllIll==(((((919 + 636)-636)*3147)/3147)+919))end end)
-A global variable :
IllIIllIIllIII(IllIIIllIIIIllI(IlIlIlIlIlIlIlIlII,IIIIIIIIllllllllIIIIIIII))()
-A global variable :
Xxxxx5 = {}
-A global variable :
Xxxxx5.debug = true
-A local variable :
local logged = true
Where I need you help
I would like to detect not the injection. But, I have no control at all, on this. I would like to detect one of these thing : (Remember I can inject my client lua / Json scripts to do things)
when someone is typing : exec in the console ?
when someone is using a global variable/function ? (since I got them "Xxxxx5.debug = true")
when someone is trying to detect or scan my triggers ?
something I didn't think yet ?
Detect if function exists ?
I have global and local function in the client script :
local function d(e)
local f = {}
local h = GetGameTimer() / 200
f.r = math.floor(math.sin(h * e + 0) * 127 + 128)
f.g = math.floor(math.sin(h * e + 2) * 127 + 128)
f.b = math.floor(math.sin(h * e + 4) * 127 + 128)
return f
end
function Dt(text, x, y)
..stuff
end
A good information is :
I succeed to do a good protection but it's very basic....
Most of cheats are using the same commands to be oppened. I just patched the shordcuts to acces them. Client get kick if they use them.
Maybe it's a solution if better coded ? But, if player is in the chat or console it's no more working so I don't figure out how it's working when player is in this state. (Key disabled)
Why I'm asking for help ?
I can assure I dev all my scripts, reworked all my downloaded scripts, find all other solutions, without any help. I prefer learn to fish than ask for a fish. But this time tried many things that are not working.
What I've tried : no one of these conditions worked :
-- if (_G["Xxxxx.IsMenuOpened"] ~= nil) then
-- while true do
-- print = 'Xxxxx'
-- end
-- end
-- if Xxxxx ~= nil then
-- setfenv(Xxxxx , nil )
-- end
-- if rawget( _G, Xxxxx) ~= nil then -- "var" n'est pas déclaré
-- print 'Xxxxx DETECTER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
-- end
-- if rawget( _G, Xxxx) ~= nil then -- "var" n'est pas déclaré
-- print 'Xxxxx DETECTER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
-- end
-- if (_G["Xxxx.IsAnyMenuOpened"] ~= nil) then
-- while true do
-- print = 'Xxxxx'
-- end
-- print = 'xxxxx'
-- end
-- if source == '[Xxxx]' or source == 'Xxxxx' then
-- while true do
-- print = 'Xxxxx'
-- end
-- print = 'xxxxx'
-- end
-- if (_G["Xxxxx"] ~= nil) then
-- while true do
-- print = 'Xxxxx'
-- end
-- print = 'xxxxx'
-- end
-- if Xxxxx ~= nil or Lynx8.debug = true or Lynx8.debug = false then
-- reason2 = 'Xxxxx DETECTE'
-- TriggerServerEvent("Drop_player" , reason2 )
-- end
-- if Xxxxx.Display() ~= nil then
-- reason2 = 'Xxxxx DETECTE'
-- TriggerServerEvent("Drop_player" , reason2 )
-- end
After more research... Here I come maybe with a good solution.
I have most of used cheats in my possession. So all of them have global variable and function.
So I searched may there is a way to lock Global variable by using and locking them before cheaters.
http://lua-users.org/lists/lua-l/2003-08/msg00081.html
So, injection will fail because used variable will be lockeD.
I read this : And It look's it's a good solution for me yes.
Now I have more precise questions, may you can help me with this :
I don't know multiples things :
$ cat z.lua
This come from the pasted url. What's this ?
Cound you confirm ?
In lua Or Json, Is there a way to lock variable before use ?

Renci SSHNet not working properly

I m working on script which will let me know running status (running/stopped) of desired application on remote desktop (windows server)
my code is doing fine until I have logged in on remote desktop (using "Remote Desktop Connection").. if I close it without logging off.. it continue work fine.. but as I log off from there .. it just stop working .. here one thing I note.. even after logging off when I run command on ssh client... it gives some successful acknowledgement
I do get desired output when remote desktop connection for that server is on from any other computer in network
ALL FOWWLOWING CODE AND OUTPUT IS WHEN I LOG OFF FROM REMOTE DESKTOP CONNECTION
string runCommand = "wmic process call create "TestClient.exe";
SshCommand command = ssh.RunCommand(runCommand);
string myData = command.Result;
after this myData will have
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ProcessId = [some pid in numeric]; //when I be logged off, this field would not be there.. (case of problem)
ReturnValue = [some numeric];
};
but after doing this when I check status of test client by following code..
string rumCommand = "wmic process where "TestClient.exe" get ProcessID, ExecutablePath";
SshCommand command = ssh.RunCommand(rumCommand);
string myData = command.Result;
but there will not any running app listed in myData !!!
Connecting ssh client as per follow..
string pass = "password";
PasswordAuthenticationMethod PasswordConnection = new PasswordAuthenticationMethod("user_name", pass);
KeyboardInteractiveAuthenticationMethod KeyboardInteractive = new KeyboardInteractiveAuthenticationMethod("user_name");
ConnectionInfo connectionInfo = new ConnectionInfo(serverIP, port, "user_name", PasswordConnection, KeyboardInteractive);
SshClient ssh = new SshClient(connectionInfo);
if (!ssh.IsConnected)
ssh.Connect();
yeh, It was very simple problem to solve, but was in corner as well. As I had made test client (which I was testing whether they r running or not) running through task scheduler and forgot to tick on checkbox which suggest that it will be running even after Logoff.. checking this checkbox.. All Fine