示例#1
0
qboolean Scr_ScriptCommand(int clientnum, const char* cmd, const char* args){

    int callback;
    int threadId;

    int i, j;

    char textbuf[MAX_STRING_CHARS];
    /* Clean control characters */
    for(i = 0, j = 0; i < sizeof(textbuf) -1 && args[i]; ++i)
    {
        textbuf[j] = args[i];

        if(textbuf[j] < ' ')
        {
            continue;
        }
        ++j;
    }
    textbuf[j] = '\0';

    callback = script_CallBacks_new[SCR_CB_SCRIPTCOMMAND];
    if(!callback){
        Scr_Error("Attempt to call a script added function without a registered callback: maps/mp/gametypes/_callbacksetup::CodeCallback_ScriptCommand\nMaybe you have not used addscriptcommand() like it is supposed to use?");
        return qfalse;
    }

    Scr_AddString(textbuf);

    Scr_AddString(cmd);

    if(clientnum < 0 || clientnum > 63)
    {
        threadId = Scr_ExecThread(callback, 2);
    }else{
        threadId = Scr_ExecEntThread(&g_entities[clientnum], callback, 2);
    }

    Scr_FreeThread(threadId);

    return qtrue;
}
示例#2
0
void gsc_exec_async_checkdone()
{
	exec_async_task *current = first_exec_async_task;

	while (current != NULL)
	{
		exec_async_task *task = current;
		current = current->next;

		if (task->done)
		{
			//push to cod
			if (Scr_IsSystemActive() && task->save && task->callback && !task->error && (scrVarPub.levelId == task->levelId))
			{
				if (task->hasargument)
				{
					switch(task->valueType)
					{
					case INT_VALUE:
						stackPushInt(task->intValue);
						break;

					case FLOAT_VALUE:
						stackPushFloat(task->floatValue);
						break;

					case STRING_VALUE:
						stackPushString(task->stringValue);
						break;

					case VECTOR_VALUE:
						stackPushVector(task->vectorValue);
						break;

					case OBJECT_VALUE:
						stackPushObject(task->objectValue);
						break;

					default:
						stackPushUndefined();
						break;
					}
				}

				stackPushArray();
				exec_outputline *output = task->output;

				while (output != NULL)
				{
					exec_outputline *next = output->next;
					stackPushString(output->content);
					stackPushArrayLast();
					delete output;
					output = next;
				}

				short ret = Scr_ExecThread(task->callback, task->save + task->hasargument);
				Scr_FreeThread(ret);
			}

			//free task
			if (task->next != NULL)
				task->next->prev = task->prev;

			if (task->prev != NULL)
				task->prev->next = task->next;
			else
				first_exec_async_task = task->next;

			delete task;
		}
	}
}
示例#3
0
void execThread(int32_t handle, uint32_t paramCount)
{
	uint16_t tid = Scr_ExecThread(SCRIPTINSTANCE_SERVER, handle, paramCount);
	Scr_FreeThread(SCRIPTINSTANCE_SERVER, tid);
}