"fork disable" disables other fork although its wrapped in fork-join - verification

i have a problem with "fork disable" that disables other processes. i already wrapped it inside fork join".is there another solution for that? that's the problematic code inside the agent:
fork
begin
fork
begin
this.collect_tr();
ap.write(collected_trans);
collected_trans.i2c_trans_cg.sample();
end
begin
wait (this.flow_is_ok == 1'b0);
end
join_any;
disable fork;
end
join
the "disable" is preventing another fork in my reference model from happening. (when i remove the disable fork of the agent, the fork in the RM does happen. i played around with some printing and it happens on the same clock)

i solved the problem. the "other fork" in the reference model that was disabled, was called from the ap write() function implementation in the reference model. since the ap.write() in the agent was disabled, the write() in the reference model is disabled as well. so i just moved the ap.write() outside of the fork.
fork
begin
fork
begin
this.collect_tr();
//ap.write(collected_trans);
//collected_trans.i2c_trans_cg.sample();
end
begin
wait (this.flow_is_ok == 1'b0);
end
join_any;
disable fork;
end
join
if(this.flow_is_ok == 1'b1)begin
ap.write(collected_trans);
collected_trans.i2c_trans_cg.sample();
end
`

If you want to disable an inner fork, you can name the fork blocks and then disable the named block.
Example:
fork: outer
begin
#10;
$display($stime, " outer");
end
begin
fork: inner
begin
#5;
$display($stime, " inner 1");
end
begin
#7;
$display($stime, " inner 2");
end
join_any
disable inner;
end
join
Output:
# 5 inner 1
# 10 outer
Full runnable example here: http://www.edaplayground.com/x/26d

Related

Postgres Raise all Exception in the end of file execution

DO $$
BEGIN
-- Check to make sure that event starts after users created
IF EXISTS (
SELECT users.id
FROM event
INNER JOIN users ON event.user_id::INT = users.id
WHERE event.start > users.created
)
THEN
RAISE NOTICE 'SUCCESSFUL %', now();
ELSE
RAISE EXCEPTION 'ERROR on % - All Event start timestamps must be created after users are created',now();
END IF;
END $$;
This exception is to check for timestamps and works well. But I want to add a similar condition and at-least 3 more exception conditions. I want to now return the exceptions at the end. I do-not want process to stop if first check fails. I want all the failed tests to be raised all at once in the end. How do I do that ? I read about stacked diagnostics bu dontt know if its the right approach or should I just use IF-else if ?
It is in the nature of an exception to interrupt processing, so you cannot simply use exceptions for that.
You could collect all exceptions in a (temporary?) table and communicate them to the client in the end, or concatenate them to a single large exception.
You could also emit the individual messages as NOTICE and throw an exception at the end.

I'm trying to do an exception with raise

I'm trying to make an exception with RAISE in PL / SQL. I did the script but when I want to run it does not show me one of the two messages and it just gives me 'anonymous block completed'.
Accept cititor prompt 'Introduceti un cititor';
DECLARE data_la_limita EXCEPTION; data_returnare varchar(10);
--cititor varchar(10);
BEGIN
SELECT s.data_dereturnat INTO data_returnare FROM fisa_imprumuturi s left join legitimatii s1
on s1.nrlegitimatie = s.nr_legitimatie left
join cititori s2 on s2.codcititor = s1.codcititor
WHERE s2.numecititor like '%&cititor%'; IF (data_returnare > sysdate ) THEN
RAISE data_la_limita;
END IF;
EXCEPTION
WHEN data_la_limita THEN
DBMS_OUTPUT.PUT_LINE('Cititorul a trecut peste data returnarii!');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Cititorul trebuie sa returneze la data: ' || data_returnare); END;
I tried to replace sysdate with a date manually ('01-May-2019') but is not working.
I'm trying to make an exception with RAISE in PL / SQL ... but when I want to run it does not show me one of the two messages
You're not seeing the messages because you are running your program in an environment which doesn't show DBMS_OUTPUT. You have coded an EXCEPTION handler which suppresses your exceptions and does not re-raise them. This is bad practice because DBMS_OUTPUT is not a mechanism for propagating exceptions: when output is suppressed or the program runs as an autonomous background routine (which is the main use of PL/SQL) there is no way to tell that the program failed.
You could enable SEVEROUTPUT (in SQL*Plus) or configure a DBMS_OUTPUT tab (in an IDE like SQL Developer). Doing this means you would see the messages next time your program runs.
But it would be better just to raise exceptions and let the calling program handle them. Given that, you should probably re-write your program something like this:
Accept cititor prompt 'Introduceti un cititor';
DECLARE
data_la_limita EXCEPTION;
data_returnare varchar(10);
--cititor varchar(10);
BEGIN
SELECT s.data_dereturnat
INTO data_returnare
FROM fisa_imprumuturi s
left join legitimatii s1 on s1.nrlegitimatie = s.nr_legitimatie left
join cititori s2 on s2.codcititor = s1.codcititor
WHERE s2.numecititor like '%&cititor%';
IF (data_returnare > sysdate ) THEN
RAISE data_la_limita;
END IF;
EXCEPTION
WHEN data_la_limita THEN
raise_application_error(-20000, 'Cititorul a trecut peste data returnarii!');
END;
It is better not to code a WHEN OTHERS handler unless we're logging the message. Even then we should execute a RAISE to pass the actual error instead of an unhelpful generic message. The calling program needs to know what went wrong so it can make the correct decision about what to do next (e.g. ignore and continue, abort and re-raise, something else).

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 ?

SQL Server Multiple DDLs Ignoring Order And in a Single Transaction

I'm trying to run multiple DDLs (around 90) on an SQL Server.
The DDLs don't contain any changes to tables, only view, stored procedures, and functions. The DDLs might have inter-dependencies between them, one STP that calls another, for example.
I don't want to start organizing the files in the correct order, because it would take too long, and I want the entire operation to fail if any one of the scripts has an error.
How can I achieve this?
My idea so far, is to start a transaction, tell the SQL to ignore errors (which I don't know how to do) run all the scripts once, tell the SQL to start throwing errors again, run all the scripts again, and then commit if everything succeeds.
Is this a good idea?
How do I CREATE \ ALTER a stored procedure or view even though it has errors?
To clarify and address some concerns...
This is not intended for production. I just don't want to leave the DB I'm testing on broken.
What I would like to achieve is this: run a big group of scripts on the server, without taking the time to order them. But if any of the scripts has an error in it, I want to rollback the entire operation.
I don't care about isolation, I only want the operation to happen as a single transaction.
Organize the files in the correct order, test the procedure on a test environment, have a validation and acceptance test, then run it in production.
While running DDL in a transaction may seem possible, in practice is not. There are many DDL statements that don't mix well with transactions. You must put the application offline, take a database backup (or create a snapshot) before the schema changes, run the tested and verified upgrade procedure (your scripts), validate the result with acceptance tests and then turn the application back online. If something fails, revert to the backup created initially (with all the implications vis-a-vis any downstream log consumer like replication, log shipping or mirroring).
This is the correct way, and as far as I'm concerned the only way. I know you'll find plenty of advice on how to do this the wrong way.
We actually do something like this to deploy our database scripts to production. We do this in an application that connects to our databases. To add to the complication, we also have 600 databases that should have the same schema, but don't really. Here's our approach:
Merge all our scripts into one big file. Injecting go's in between every single file. This makes it look like there's one very long script. We do a simple ordering based on what the coders requested.
Split everything into "go blocks". Since go isn't legal sql, we split them up into multiple blocks that get executed one at a time.
Open a database connection.
Start a transaction.
for each go block:
Make sure the transaction is still active. (This is VERY important. I'll explain why in a bit.)
Run the code, recording the errors.
If there were any errors, rollback. Otherwise, commit.
In our multi database set up, we do this whole thing twice. Run through every database once, "testing" the code to make sure there are no errors on any database, and then go back and run them again "for real".
Now on to why you need to make sure the transaction is still active. There are some commands that will rollback your transaction on error! Imagine our surprise the first time we found this out... Everything before the error was rolled back, but everything after was committed. If there is an error, however, nothing in that same block gets committed, so it's all good.
Below is our core of our execution code. We use a wrapper around SqlClient, but it should look very similar to SqlClient.
Dim T = New DBTransaction(client)
For Each block In scriptBlocks
If Not T.RestartIfNecessary Then
exceptionCount += 1
Log("Could not (re)start the transaction for {0}. Not executing the rest of the script.", scriptName)
Exit For
End If
Debug.Assert(T.IsInTransaction)
Try
client.Text = block
client.ExecNonQuery()
Catch ex As Exception
exceptionCount += 1
Log(ex.Message + " on {0} executing: '{1}'", client.Connection.Database, block.Replace(vbNewLine, ""))
End Try
Next
If exceptionCount > 0 Then Log("There were {0} exceptions while executing {1}.", exceptionCount, scriptName)
If testing OrElse
exceptionCount > 0 Then
Try
T.Rollback()
Log("Rolled back all changes for {0} on {1}.", scriptName, client.Connection.Database)
Catch ex As Exception
Log("Could not roll back {0} on {1}: {2}", scriptName, client.Connection.Database, ex.Message)
If Debugger.IsAttached Then
Debugger.Break()
End If
End Try
Else
T.Commit()
Log("Successfully committed all changes for {0} on {1}.", scriptName, client.Connection.Database)
End If
Return exceptionCount
Class DBTransaction
Private _tName As String
Public ReadOnly Property name() As String
Get
Return _tName
End Get
End Property
Private _client As OB.Core2.DB.Client
Public Sub New(client As OB.Core2.DB.Client, Optional name As String = Nothing)
If name Is Nothing Then
name = "T" & Guid.NewGuid.ToString.Replace("-", "").Substring(0, 30)
End If
_tName = name
_client = client
End Sub
Public Function Begin() As Boolean
Return RestartIfNecessary()
End Function
Public Function RestartIfNecessary() As Boolean
Try
_client.Text = "IF NOT EXISTS (Select transaction_id From sys.dm_tran_active_transactions where name = '" & name & "') BEGIN BEGIN TRANSACTION " & name & " END"
_client.ExecNonQuery()
Return IsInTransaction()
Catch ex As Exception
Return False
End Try
End Function
Public Function IsInTransaction() As Boolean
_client.Text = "Select transaction_id From sys.dm_tran_active_transactions where name = '" & name & "'"
Dim scalar As String = _client.ExecScalar
Return scalar <> ""
End Function
Public Sub Rollback()
_client.Text = "ROLLBACK TRANSACTION " & name
_client.ExecNonQuery()
End Sub
Public Sub Commit()
_client.Text = "COMMIT TRANSACTION " & name
_client.ExecNonQuery()
End Sub
End Class
You have a good answer, here is "hack" answer. For the case "You cannot do this, but if you want it very much, then go on". I'm quite confident that you will not achieve what you are thinking of, therefore
DO FULL BACKUP!
Assuming there are no COMMIT or GO statements (explicit or !implicit!) in any of these files, the only thing you need to do is to run them in a single transaction. Combine them in one file, wrap in a transaction, and run.
How to combine 90 files in 1 file:
If sorting by name brings them in right order, then run this from folder with files in command prompt:
FOR /F "tokens=1" %G IN ('dir /b /-d /o:n *.sql') DO (
type %G >> Big_SQL_Script.sql && echo. >> Big_SQL_Script.sql
)
If order is random, then create a list of files dir /b /-d *.sql > File_Name_List.txt and order it manually. Then run:
FOR /F "tokens=1" %G IN (File_Name_List.txt) DO (
type %G >> Big_SQL_Script.sql && echo. >> Big_SQL_Script.sql
)
This way you can concatenate 90 files in automated order. Run and see what happens.
Good luck!

Handling Lua errors in a clean and effective manner

I'm currently trying to code an add-on the popular game World Of Warcraft for a friend. I don't understand too much about the game myself and debugging it within the game is difficult as he's having to do all the testing.
I'm pretty new to Lua, so this may be a very easy question to answer. But when a Lua error occurs in WoW it throws it on screen and gets in the way, this is very bad to a game player as it will stop their gameplay if it throws the exception at the wrong time. I'm looking for a way to cleanly handle the error being thrown. Here's my code so far for the function.
function GuildShoppingList:gslSlashProc()
-- Actions to be taken when command /gsl is procced.
BankTab = GetCurrentGuildBankTab()
BankInfo = GetGuildBankText(BankTab)
local Tabname, Tabicon, TabisViewable, TabcanDeposit, TabnumWithdrawals, remainingWithdrawals = GetGuildBankTabInfo(BankTab)
p1 = BankInfo:match('%-%- GSL %-%-%s+(.*)%s+%-%- ENDGSL %-%-')
if p1 == nil then
self:Print("GSL could not retrieve information, please open the guild bank and select the info tab allow data collection to be made")
else
self:Print("Returning info for: "..Tabname)
for id,qty in p1:gmatch('(%d+):(%d+)') do
--do something with those keys:
local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(id);
local iSum = qty/iStackCount
self:Print("We need "..sLink.." x"..qty.."("..iSum.." stacks of "..iStackCount..")")
end
end
end
The problem being when checking to see if p1 is nil, it still throws a Lua error about trying to call p1 as nil. It will be nil at times and this needs to be handled correctly.
What would be the correct most efficient way to go about this?
You might want to wrap your function in a pcall or xpcall which enables you to intercept any error thrown by Lua.
Aside of that, I personally find this construct easier to read:
p1=string.match(str,pat)
if p1 then
-- p1 is valid, eg not nil or false
else
-- handle the problems
end