Beispiel #1
0
int CNetServer::Update()
{
	int64 Now = time_get();
	for(int i = 0; i < MaxClients(); i++)
	{
		m_aSlots[i].m_Connection.Update();
		if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR)
		{
			if(Now - m_aSlots[i].m_Connection.ConnectTime() < time_freq() && NetBan())
			{
				if(NetBan()->BanAddr(ClientAddr(i), 60, "Stressing network") == -1)
					Drop(i, m_aSlots[i].m_Connection.ErrorString());
			}
			else
				Drop(i, m_aSlots[i].m_Connection.ErrorString());
		}
	}

	return 0;
}
Beispiel #2
0
void snap_free_id(int id)
{
	dbg_assert(snap_ids[id].state == 1, "id is not alloced");

	snap_id_inusage--;
	snap_ids[id].state = 2;
	snap_ids[id].timeout = time_get()+time_freq()*5;
	snap_ids[id].next = -1;
	
	if(snap_last_timed_id != -1)
	{
		snap_ids[snap_last_timed_id].next = id;
		snap_last_timed_id = id;
	}
	else
	{
		snap_first_timed_id = id;
		snap_last_timed_id = id;
	}
}
Beispiel #3
0
void CSnapIDPool::FreeID(int Id)
{
	dbg_assert(m_aIDs[Id].m_State == 1, "id is not alloced");

	m_InUsage--;
	m_aIDs[Id].m_State = 2;
	m_aIDs[Id].m_Timeout = time_get()+time_freq()*5;
	m_aIDs[Id].m_Next = -1;
	
	if(m_LastTimed != -1)
	{
		m_aIDs[m_LastTimed].m_Next = Id;
		m_LastTimed = Id;
	}
	else
	{
		m_FirstTimed = Id;
		m_LastTimed = Id;
	}
}
/*
static void ui_pg_list_start_roll(control_t *p_cont)
{
  roll_param_t p_param = {0};
  MT_ASSERT(p_cont != NULL);

  gui_stop_roll(p_cont);

  p_param.pace = ROLL_SINGLE;
  p_param.style = ROLL_LR;
  p_param.repeats = 0;
  p_param.is_force = FALSE;

  gui_start_roll(p_cont, &p_param);

}
*/
void epg_list_update_time(control_t *p_info, BOOL is_paint)
{
  utc_time_t cur_time;
  u8 asc_str[10];

  time_get(&cur_time, FALSE);

//  printf_time(&cur_time, "epg_list_update_time");

  sprintf((char *)asc_str, "%.2d/%.2d", cur_time.month, cur_time.day);
  mbox_set_content_by_ascstr(p_info, 0, asc_str);

  sprintf((char *)asc_str, "%.2d:%.2d", cur_time.hour, cur_time.minute);
  mbox_set_content_by_ascstr(p_info, 1, asc_str);

  if(is_paint)
  {
    ctrl_paint_ctrl(p_info, TRUE);
  }
}
Beispiel #5
0
void CServerBrowser::CBFTrackPacket(int TrackID, void *pCallbackUser)
{
	if(!pCallbackUser)
		return;

	CServerBrowser *pSelf = (CServerBrowser *)pCallbackUser;
	CServerEntry *pEntry = pSelf->m_pFirstReqServer;
	while(1)
	{
		if(!pEntry)	// no more entries
			break;

		if(pEntry->m_TrackID == TrackID)	// got it -> update
		{
			pEntry->m_RequestTime = time_get();
			break;
		}

		pEntry = pEntry->m_pNextReq;
	}
}
Beispiel #6
0
void CParticleEmitter::OnReset()
{
    //Testing
    m_Particle.SetDefault();
	m_Particle.m_Spr = 7;
	m_Particle.m_Vel = vec2(0, -440);
	m_Particle.m_LifeSpan = 0.5f + frandom()*0.5f;
	m_Particle.m_Rot = pi * 10.0f * (frandom() - 0.5f);
	m_Particle.m_Rotspeed = pi * 2;
	m_Particle.m_StartSize = 36.0f;
	m_Particle.m_EndSize = 0;
	m_Particle.m_Friction = 0.8;
	m_Particle.m_Gravity.y = frandom()*-500.0f;
	m_Particle.m_Gravity.x = 0.0f;
	m_Particle.m_FlowAffected = 5;
	m_Particle.m_Pos = vec2(1010, 550);
	m_Particle.m_Color = vec4(1,1,1, 0.1);

	m_ParticlesPerSec = 360;
	m_LastParticle = time_get();
}
Beispiel #7
0
void CGameContext::SendVoteSet(int Type, int ToClientID)
{
	CNetMsg_Sv_VoteSet Msg;
	if(m_VoteCloseTime)
	{
		Msg.m_ClientID = m_VoteCreator;
		Msg.m_Type = Type;
		Msg.m_Timeout = (m_VoteCloseTime-time_get())/time_freq();
		Msg.m_pDescription = m_aVoteDescription;
		Msg.m_pReason = m_aVoteReason;
	}
	else
	{
		Msg.m_Type = Type;
		Msg.m_Timeout = 0;
		Msg.m_ClientID = m_VoteCreator;
		Msg.m_pDescription = "";
		Msg.m_pReason = "";
	}
	Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ToClientID);
}
static void nvod_video_calc_left_time()
{
  time_shifted_svc_evt_t *p_ts_svc_evt = NULL;
  u32 total_left_second = 0;
  utc_time_t end_time = {0};
  utc_time_t cur_time = {0};

  p_ts_svc_evt = ui_get_playing_nvod_time_shifted_svc_evt();

  time_get(&cur_time,TRUE);
   
  g_past_second = time_dec(&cur_time, &p_ts_svc_evt->start_time);

  memset(&left_time, 0, sizeof(utc_time_t));
  memcpy(&end_time, &p_ts_svc_evt->start_time, sizeof(utc_time_t));
  time_add(&end_time, &p_ts_svc_evt->drt_time);
  total_left_second = time_dec(&end_time, &cur_time);
  left_time.hour = (u8)(total_left_second / 3600);
  left_time.minute = (u8)((total_left_second % 3600)/60);
  left_time.second = (u8)((total_left_second % 60));
}
Beispiel #9
0
void CParticles::OnRender()
{
	if(Client()->State() < IClient::STATE_ONLINE)
		return;

	static int64 LastTime = 0;
	int64 t = time_get();

	if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
	{
		const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
		if(!pInfo->m_Paused)
			Update((float)((t-LastTime)/(double)time_freq())*pInfo->m_Speed);
	}
	else
	{
		if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED))
			Update((float)((t-LastTime)/(double)time_freq()));
	}

	LastTime = t;
}
Beispiel #10
0
void perf_start(PERFORMACE_INFO *info)
{
	if(info->tick != perf_tick)
	{
		info->parent = current;
		info->first_child = 0;
		info->next_child = 0;
		
		if(info->parent)
		{
			info->next_child = info->parent->first_child;
			info->parent->first_child = info;
		}
		
		info->tick = perf_tick;
		info->biggest = 0;
		info->total = 0;
	}
	
	current = info;
	current->start = time_get();
}
Beispiel #11
0
Datei: oid.c Projekt: miaofng/ulp
static int oid_measure_voltage(int pin0, int pin1)
{
	int mv = -1;
	dmm_config("V");
	matrix_reset();
	matrix_connect(RBUS_VIP, oid_pinmap[pin0]);
	matrix_connect(RBUS_VIN, oid_pinmap[pin1]);
	if(!matrix_execute()) {
		oid_show_progress(PROGRESS_WAIT);
		#if 1
		time_t deadline = time_get(600);
		while(time_left(deadline) > 0) {
			instr_update();
		}
		#else
		sys_mdelay(300);
		#endif
		mv = dmm_read();
		mv = (mv < 0) ? (-mv) : mv;
	}
	return mv;
}
void nvod_data_delete_overdue(void *p_data)
{
  nvod_db_t *p_nvod = (nvod_db_t *)p_data;
  nvod_reference_svc_evt_t *p_ref_evt = NULL;
  time_shifted_svc_evt_t *p_shift_evt = NULL;
  utc_time_t sys_time = {0};
  utc_time_t end_time = {0};
  RET_CODE ret = SUCCESS;
  
  MT_ASSERT(p_nvod != NULL);

  time_get(&sys_time, TRUE);

  p_ref_evt = p_nvod->p_ref_evt_head;
  while (p_ref_evt)
  {
    if (p_ref_evt->shift_evt_cnt
      && p_ref_evt->ref_svc_idx == p_nvod->cur_ref_svc_idx)
    {
      p_shift_evt = p_ref_evt->p_shift_evt;
      MT_ASSERT(p_shift_evt != NULL);
      
      memcpy(&end_time, &p_shift_evt->start_time, sizeof(utc_time_t));
      evt_tadd(&end_time, &p_shift_evt->drt_time);

      /*!Compare end time of system time*/
      if (EVT_TCMP(&end_time, &sys_time) != 1)
      {
        p_ref_evt->p_shift_evt = p_shift_evt->p_next_evt;
        p_ref_evt->shift_evt_cnt --;
        ret = lib_memf_free(&p_nvod->shift_evt_memf, p_shift_evt);
        MT_ASSERT(ret == SUCCESS);
      }
    }
    
    p_ref_evt = p_ref_evt->p_next_evt;
  }
  
}
Beispiel #13
0
void CCamera::Move(vec2 Pos, float Zoom, bool Smooth)
{
	static bool First = true;
	Pos *= 32.0f;
	if (First || !Smooth)
	{
		m_WantedPos = Pos;
		m_Zoom = Zoom;
		First = false;
		return;
	}

	if (m_WantedPos != Pos)
	{
		m_PrevPos = m_Center;
		m_WantedPos = Pos;
		m_PrevZoom = m_Zoom;
		m_WantedZoom = Zoom;
		m_LastMove = time_get();
		m_Sway = false;
	}
}
Beispiel #14
0
void CHAT::add_line(int client_id, int team, const char *line)
{
	current_line = (current_line+1)%MAX_LINES;
	lines[current_line].time = time_get();
	lines[current_line].client_id = client_id;
	lines[current_line].team = team;
	lines[current_line].name_color = -2;

	if(client_id == -1) // server message
	{
		str_copy(lines[current_line].name, "*** ", sizeof(lines[current_line].name));
		str_format(lines[current_line].text, sizeof(lines[current_line].text), "%s", line);
	
	} else {
		lines[current_line].name_color = -1;
		
		str_copy(lines[current_line].name, gameclient.clients[client_id].name, sizeof(lines[current_line].name));
		str_format(lines[current_line].text, sizeof(lines[current_line].text), ": %s", line);
	}
	
	dbg_msg( "chat", "%s%s", lines[current_line].name, lines[current_line].text );
}
Beispiel #15
0
void CMenus::OnStateChange(int NewState, int OldState)
{
	// reset active item
	UI()->SetActiveItem(0);

	if(NewState == IClient::STATE_OFFLINE)
	{
		if(OldState >= IClient::STATE_ONLINE)
			m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0));
		m_Popup = POPUP_NONE;
		if(Client()->ErrorString() && Client()->ErrorString()[0] != 0)
		{
			if(str_find(Client()->ErrorString(), "password"))
			{
				m_Popup = POPUP_PASSWORD;
				UI()->SetHotItem(&g_Config.m_Password);
				UI()->SetActiveItem(&g_Config.m_Password);
			}
			else
				m_Popup = POPUP_DISCONNECTED;
		}
	}
	else if(NewState == IClient::STATE_LOADING)
	{
		m_Popup = POPUP_CONNECTING;
		m_DownloadLastCheckTime = time_get();
		m_DownloadLastCheckSize = 0;
		m_DownloadSpeed = 0.0f;
		//client_serverinfo_request();
	}
	else if(NewState == IClient::STATE_CONNECTING)
		m_Popup = POPUP_CONNECTING;
	else if (NewState == IClient::STATE_ONLINE || NewState == IClient::STATE_DEMOPLAYBACK)
	{
		m_Popup = POPUP_NONE;
		SetActive(false);
	}
}
Beispiel #16
0
void CHud::RenderGameTimer()
{
	// MineTee
    CServerInfo Info;
    Client()->GetServerInfo(&Info);
    if (str_find_nocase(Info.m_aGameType, "minetee"))
        return;
    //

	float Half = 300.0f*Graphics()->ScreenAspect()/2.0f;

	if(!(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_SUDDENDEATH))
	{
		char Buf[32];
		int Time = 0;
		if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && !m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
		{
			Time = m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit*60 - ((Client()->GameTick()-m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick)/Client()->GameTickSpeed());

			if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)
				Time = 0;
		}
		else
			Time = (Client()->GameTick()-m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick)/Client()->GameTickSpeed();

		str_format(Buf, sizeof(Buf), "%d:%02d", Time/60, Time%60);
		float FontSize = 10.0f;
		float w = TextRender()->TextWidth(0, FontSize, Buf, -1);
		// last 60 sec red, last 10 sec blink
		if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && Time <= 60 && !m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
		{
			float Alpha = Time <= 10 && (2*time_get()/time_freq()) % 2 ? 0.5f : 1.0f;
			TextRender()->TextColor(1.0f, 0.25f, 0.25f, Alpha);
		}
		TextRender()->Text(0, Half-w/2, 2, FontSize, Buf, -1);
		TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
	}
}
Beispiel #17
0
void o2pt_pulse(int ch, float i, float hz)
{
	/*
	PA4		IPUL_A		DAC_OUT1
	PA5		IPUL_B		DAC_OUT2
	*/
	float vset, dset;
	int regv;

	/*iset = vset / rifb = > vset = iset * rifb */
	vset = i * rifb; //30mA * 50ohm = 1500mv
	dset = vset * 4096 / vref;
	regv = (int) dset;

	/*limit*/
	regv = (regv > 4095) ? 4095 : regv;
	regv = (regv < 0)? 0 : regv;

	/*change current & o2pt mode
	PC8		EPUL_A
	PC12	EPUL_B
	*/
	if(ch == 0) {
		DAC->DHR12R1 = regv;
		GPIOC->BSRR = GPIO_Pin_8; //EPUL = 1
	}
	else {
		DAC->DHR12R2 = regv;
		GPIOC->BSRR = GPIO_Pin_12; //EPUL = 1
	}

	//avoid switch too fast
	hz = (hz > 50.0f) ? 50.0f : hz;
	ch = (ch > 0) ? 1 : 0;

	o2pt_pulse_ms[ch] = (int) (1000.0f / hz);
	o2pt_pulse_timer[ch] = time_get(o2pt_pulse_ms[ch]);
}
Beispiel #18
0
/*
 * Must be called with interrupts disabled,
 * and with the CPU time counter counting.
 */
void cpustats_tick()
{
	struct timestamp ts;
	struct timestamp diff;
	int usec;

	if(enter_count == 0) {
		printf("cpustats_tick() called with enter_count == 0!\n");
		return;
	}

	time_get(&ts);
	time_diff(&diff, &ts, &first_enter);
	time_add(&acc, &diff);

	usec = acc.sec*1000000+acc.usec;
	load = usec/10000;

	first_enter.sec = ts.sec;
	first_enter.usec = ts.usec;
	acc.sec = 0;
	acc.usec = 0;
}
Beispiel #19
0
void CNetTokenCache::SendPacketConnless(const NETADDR *pAddr, const void *pData, int DataSize, CSendCBData *pCallbackData)
{
	TOKEN Token = GetToken(pAddr);
	if(Token != NET_TOKEN_NONE)
	{
		CNetBase::SendPacketConnless(m_Socket, pAddr, Token,
			m_pTokenManager->GenerateToken(pAddr), pData, DataSize);
	}
	else
	{
		FetchToken(pAddr);

		// store the packet for future sending
		CConnlessPacketInfo **ppInfo = &m_pConnlessPacketList;
		while(*ppInfo)
			ppInfo = &(*ppInfo)->m_pNext;
		*ppInfo = new CConnlessPacketInfo();
		mem_copy((*ppInfo)->m_aData, pData, DataSize);
		(*ppInfo)->m_Addr = *pAddr;
		(*ppInfo)->m_DataSize = DataSize;
		int64 Now = time_get();
		(*ppInfo)->m_Expiry = Now + time_freq() * NET_TOKENCACHE_PACKETEXPIRY;
		(*ppInfo)->m_LastTokenRequest = Now;
		(*ppInfo)->m_pNext = 0;
		if(pCallbackData)
		{
			(*ppInfo)->m_pfnCallback = pCallbackData->m_pfnCallback;
			(*ppInfo)->m_pCallbackUser = pCallbackData->m_pCallbackUser;
			pCallbackData->m_TrackID = (*ppInfo)->m_TrackID;
		}
		else
		{
			(*ppInfo)->m_pfnCallback = 0;
			(*ppInfo)->m_pCallbackUser = 0;
		}
	}
}
Beispiel #20
0
void CBroadcast::OnMessage(int MsgType, void *pRawMsg)
{
	CALLSTACK_ADD();

	if(MsgType == NETMSGTYPE_SV_BROADCAST)
	{
		CNetMsg_Sv_Broadcast *pMsg = (CNetMsg_Sv_Broadcast *)pRawMsg;
		str_copy(m_aBroadcastText, pMsg->m_pMessage, sizeof(m_aBroadcastText));
		CTextCursor Cursor;
		TextRender()->SetCursor(&Cursor, 0, 0, 12.0f, TEXTFLAG_STOP_AT_END);
		Cursor.m_LineWidth = 300*Graphics()->ScreenAspect();
		TextRender()->TextEx(&Cursor, m_aBroadcastText, -1);
		m_BroadcastRenderOffset = 150*Graphics()->ScreenAspect()-Cursor.m_X/2;
		m_BroadcastTime = time_get()+time_freq()*10;
		if (g_Config.m_ClPrintBroadcasts)
		{
			char aBuf[1024];
			int i, ii;
			for (i = 0, ii = 0; i < str_length(m_aBroadcastText); i++)
			{
				if (m_aBroadcastText[i] == '\n')
				{
					aBuf[ii] = '\0';
					ii = 0;
					m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aBuf, true);
				}
				else
				{
					aBuf[ii] = m_aBroadcastText[i];
					ii++;
				}
			}
			aBuf[ii] = '\0';
			m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "broadcast", aBuf, true);
		}
	}
}
Beispiel #21
0
CMenus::CMenus()
{
	m_Popup = POPUP_NONE;
	m_ActivePage = PAGE_INTERNET;
	m_GamePage = PAGE_GAME;
	
	m_NeedRestartGraphics = false;
	m_NeedRestartSound = false;
	m_NeedSendinfo = false;
	m_MenuActive = true;
	m_UseMouseButtons = true;
	
	m_EscapePressed = false;
	m_EnterPressed = false;
	m_DeletePressed = false;
	m_NumInputEvents = 0;
	
	m_LastInput = time_get();
	
	str_copy(m_aCurrentDemoFolder, "demos", sizeof(m_aCurrentDemoFolder));
	m_aCallvoteReason[0] = 0;

	m_FriendlistSelectedIndex = -1;
}
Beispiel #22
0
void pars_nick(void) {
    strncpy(status->channel, packet, NICK_MAXLEN);
    strncpy(status->nick, pars_word(), NICK_MAXLEN);
    if (!config->packet_qchat) {
        pars_word(); status->gender = pars_number();
    }
    user_nick();
    chat_nick();
    if (user_ignore()) return;
    snprintf(message, MSG_SIZE, PARS_NICK, time_get(), status->channel, status->nick);
#ifdef  TCP
    write_tcp(status->chnl[0].name);
#endif  /* TCP */
    if (!user_ignore() && config->verbose) {
        write_log(config->log_main);
        write_str(status->chnl[0].name, COL_SYSTEM);
    }
    refresh_room();
    screen_show();
    refresh_input();
    string_show();
    if ((!config->my_only || !strncmp(status->room->name, status->channel, CHANNEL_MAXLEN)) &&
        (config->mode == MOD_NORMAL)) beep_system();
}
Beispiel #23
0
void CNetTokenCache::SendPacketConnless(const NETADDR *pAddr, const void *pData, int DataSize)
{
	TOKEN Token = GetToken(pAddr);
	if(Token != NET_TOKEN_NONE)
	{
		CNetBase::SendPacketConnless(m_Socket, pAddr, Token,
			m_pTokenManager->GenerateToken(pAddr), pData, DataSize);
	}
	else
	{
		FetchToken(pAddr);

		// store the packet for future sending
		CConnlessPacketInfo **ppInfo = &m_pConnlessPacketList;
		while(*ppInfo)
			ppInfo = &(*ppInfo)->m_pNext;
		*ppInfo = new CConnlessPacketInfo();
		mem_copy((*ppInfo)->m_aData, pData, DataSize);
		(*ppInfo)->m_Addr = *pAddr;
		(*ppInfo)->m_DataSize = DataSize;
		(*ppInfo)->m_Expiry = time_get() + time_freq() * NET_TOKENCACHE_PACKETEXPIRY;
		(*ppInfo)->m_pNext = 0;
	}
}
Beispiel #24
0
void CLuaFile::Tick()
{
    if (!g_Config.m_SvLua)
        return;

    ErrorFunc(m_pLua);
    MySQLTick(); //garbage collector -> clear old results that aren't fetched by lua
    m_pLuaShared->Tick();

    if (!FunctionExist("Tick"))
        return;

    FunctionPrepare("Tick");
    PushInteger((int)(time_get() * 1000 / time_freq()));
    PushInteger(m_pServer->Server()->Tick());
    FunctionExec();

	if (m_pServer->Server()->Tick() % (m_pServer->Server()->TickSpeed() * 60) == 0)
		dbg_msg("lua", "%i kiB", lua_gc(m_pLua, LUA_GCCOUNT, 0));

    lua_gc(m_pLua, LUA_GCCOLLECT, 1000);

    ErrorFunc(m_pLua);
}
Beispiel #25
0
void CGameContext::StartVote(const char *pDesc, const char *pCommand)
{
	// check if a vote is already running
	if(m_VoteCloseTime)
		return;

	// reset votes
	m_VoteEnforce = VOTE_ENFORCE_UNKNOWN;
	for(int i = 0; i < MAX_CLIENTS; i++)
	{
		if(m_apPlayers[i])
		{
			m_apPlayers[i]->m_Vote = 0;
			m_apPlayers[i]->m_VotePos = 0;
		}
	}
	
	// start vote
	m_VoteCloseTime = time_get() + time_freq()*25;
	str_copy(m_aVoteDescription, pDesc, sizeof(m_aVoteDescription));
	str_copy(m_aVoteCommand, pCommand, sizeof(m_aVoteCommand));
	SendVoteSet(-1);
	m_VoteUpdate = true;
}
Beispiel #26
0
void menu_timer_status (void) {
    usb_tx_string_P(PSTR("TZN="));
    menu_print_int(time_zone_get());
    menu_send_n();
    usb_tx_string_P(PSTR("DST="));
    if (time_dst_get())
    {
        menu_send_1();
    }
    else	{
        menu_send_0();
    }
    usb_tx_string_P(PSTR("UTC="));
    menu_print_int(time_get());
    menu_send_n();
    usb_tx_string_P(PSTR("H24="));
    if (time_is_current())
    {
        menu_send_1();
    }
    else	{
        menu_send_0();
    }
    usb_tx_string_P(PSTR("ALM="));
    menu_print_int(time_alarm_get());
    menu_send_n();
    usb_tx_string_P(PSTR("ALS="));
    if (time_alarm_active())
    {
        menu_send_1();
    }
    else	{
        menu_send_0();
    }

}
Beispiel #27
0
int CControls::SnapInput(int *pData, int *pPredictionData)
{
	static int64 LastSendTime = 0;
	bool Send = false;

	// update player state
	if(m_pClient->m_pChat->IsActive())
		m_InputData.m_PlayerFlags = PLAYERFLAG_CHATTING;
	else if(m_pClient->m_pMenus->IsActive())
		m_InputData.m_PlayerFlags = PLAYERFLAG_IN_MENU;
	else
		m_InputData.m_PlayerFlags = PLAYERFLAG_PLAYING;

	if(m_pClient->m_pScoreboard->Active() || m_pClient->m_UpdateScoreboard)
		m_InputData.m_PlayerFlags |= PLAYERFLAG_SCOREBOARD;
    m_pClient->m_UpdateScoreboard = false;

	if(m_LastData.m_PlayerFlags != m_InputData.m_PlayerFlags)
		Send = true;

	m_LastData.m_PlayerFlags = m_InputData.m_PlayerFlags;

	// we freeze the input if chat or menu is activated
	if(!(m_InputData.m_PlayerFlags&PLAYERFLAG_PLAYING))
	{
		OnReset();

		mem_copy(pData, &m_InputData, sizeof(m_InputData));

		// send once a second just to be sure
		if(time_get() > LastSendTime + time_freq())
			Send = true;
	}
	else
	{

		m_InputData.m_TargetX = (int)m_MousePos.x;
		m_InputData.m_TargetY = (int)m_MousePos.y;
		if(!m_InputData.m_TargetX && !m_InputData.m_TargetY)
		{
			m_InputData.m_TargetX = 1;
			m_MousePos.x = 1;
		}

		// set direction
		m_InputData.m_Direction = 0;
		if(m_InputDirectionLeft && !m_InputDirectionRight)
			m_InputData.m_Direction = -1;
		if(!m_InputDirectionLeft && m_InputDirectionRight)
			m_InputData.m_Direction = 1;

		// stress testing
		if(g_Config.m_DbgStress)
		{
			float t = Client()->LocalTime();
			mem_zero(&m_InputData, sizeof(m_InputData));

			m_InputData.m_Direction = ((int)t/2)&1;
			m_InputData.m_Jump = ((int)t);
			m_InputData.m_Fire = ((int)(t*10));
			m_InputData.m_Hook = ((int)(t*2))&1;
			m_InputData.m_WantedWeapon = ((int)t)%NUM_WEAPONS;
			m_InputData.m_TargetX = (int)(sinf(t*3)*100.0f);
			m_InputData.m_TargetY = (int)(cosf(t*3)*100.0f);
		}

        m_PredictionData = m_InputData;

        if (m_pClient->m_pLuaBinding) //make sure that we have this class
        {
            //Lua
            m_pClient->m_pLuaBinding->m_ControlDirectionPre = m_InputData.m_Direction;
            m_pClient->m_pLuaBinding->m_ControlFirePre = m_InputData.m_Fire;
            m_pClient->m_pLuaBinding->m_ControlJumpPre = m_InputData.m_Jump;
            m_pClient->m_pLuaBinding->m_ControlHookPre = m_InputData.m_Hook;
            m_pClient->m_pLuaBinding->m_ControlWeaponPre = m_InputData.m_WantedWeapon;
            m_pClient->m_pLuaBinding->m_ControlTargetXPre = m_InputData.m_TargetX;
            m_pClient->m_pLuaBinding->m_ControlTargetYPre = m_InputData.m_TargetY;

            int EventID = m_pClient->m_pLua->m_pEventListener->CreateEventStack();
            m_pClient->m_pLua->m_pEventListener->OnEvent("OnControlChange");

            if (m_pClient->m_pLuaBinding->m_ControlDirectionIsSet)
            {
                m_InputData.m_Direction = m_pClient->m_pLuaBinding->m_ControlDirection;
            }
            if (m_pClient->m_pLuaBinding->m_ControlFireIsSet)
            {
                m_InputData.m_Fire = m_pClient->m_pLuaBinding->m_ControlFire;
            }
            if (m_pClient->m_pLuaBinding->m_ControlHookIsSet)
            {
                m_InputData.m_Hook = m_pClient->m_pLuaBinding->m_ControlHook;
            }
            if (m_pClient->m_pLuaBinding->m_ControlJumpIsSet)
            {
                m_InputData.m_Jump = m_pClient->m_pLuaBinding->m_ControlJump;
            }
            if (m_pClient->m_pLuaBinding->m_ControlWeaponIsSet)
            {
                m_InputData.m_WantedWeapon = m_pClient->m_pLuaBinding->m_ControlWeapon;
            }
            if (m_pClient->m_pLuaBinding->m_ControlTargetXIsSet)
            {
                m_InputData.m_TargetX = m_pClient->m_pLuaBinding->m_ControlTargetX;
            }
            if (m_pClient->m_pLuaBinding->m_ControlTargetYIsSet)
            {
                m_InputData.m_TargetY = m_pClient->m_pLuaBinding->m_ControlTargetY;
            }

            if (m_pClient->m_pLuaBinding->m_ControlDirectionPredictedIsSet)
            {
                m_PredictionData.m_Direction = m_pClient->m_pLuaBinding->m_ControlDirectionPredicted;
            }
            if (m_pClient->m_pLuaBinding->m_ControlFirePredictedIsSet)
            {
                m_PredictionData.m_Fire = m_pClient->m_pLuaBinding->m_ControlFirePredicted;
            }
            if (m_pClient->m_pLuaBinding->m_ControlHookPredictedIsSet)
            {
                m_PredictionData.m_Hook = m_pClient->m_pLuaBinding->m_ControlHookPredicted;
            }
            if (m_pClient->m_pLuaBinding->m_ControlJumpPredictedIsSet)
            {
                m_PredictionData.m_Jump = m_pClient->m_pLuaBinding->m_ControlJumpPredicted;
            }
            if (m_pClient->m_pLuaBinding->m_ControlWeaponPredictedIsSet)
            {
                m_PredictionData.m_WantedWeapon = m_pClient->m_pLuaBinding->m_ControlWeaponPredicted;
            }
            if (m_pClient->m_pLuaBinding->m_ControlTargetXPredictedIsSet)
            {
                m_PredictionData.m_TargetX = m_pClient->m_pLuaBinding->m_ControlTargetXPredicted;
            }
            if (m_pClient->m_pLuaBinding->m_ControlTargetYPredictedIsSet)
            {
                m_PredictionData.m_TargetY = m_pClient->m_pLuaBinding->m_ControlTargetYPredicted;
            }
        }
		// check if we need to send input
		if(m_InputData.m_Direction != m_LastData.m_Direction) Send = true;
		else if(m_InputData.m_Jump != m_LastData.m_Jump) Send = true;
		else if(m_InputData.m_Fire != m_LastData.m_Fire) Send = true;
		else if(m_InputData.m_Hook != m_LastData.m_Hook) Send = true;
		else if(m_InputData.m_WantedWeapon != m_LastData.m_WantedWeapon) Send = true;
		else if(m_InputData.m_NextWeapon != m_LastData.m_NextWeapon) Send = true;
		else if(m_InputData.m_PrevWeapon != m_LastData.m_PrevWeapon) Send = true;

		// send at at least 10hz
		if(time_get() > LastSendTime + time_freq()/25)
			Send = true;
	}

	// copy and return size
	m_LastData = m_InputData;

	if(!Send)
		return 0;

	LastSendTime = time_get();
	mem_copy(pData, &m_InputData, sizeof(m_InputData));
	mem_copy(pPredictionData, &m_PredictionData, sizeof(m_PredictionData));
	return sizeof(m_InputData);
}
Beispiel #28
0
void CGameClient::OnRender()
{
	/*Graphics()->Clear(1,0,0);

	menus->render_background();
	return;*/
	/*
	Graphics()->Clear(1,0,0);
	Graphics()->MapScreen(0,0,100,100);

	Graphics()->QuadsBegin();
		Graphics()->SetColor(1,1,1,1);
		Graphics()->QuadsDraw(50, 50, 30, 30);
	Graphics()->QuadsEnd();

	return;*/

	// update the local character and spectate position
	UpdatePositions();

	// dispatch all input to systems
	DispatchInput();

	// render all systems
	for(int i = 0; i < m_All.m_Num; i++)
		m_All.m_paComponents[i]->OnRender();

	// clear new tick flags
	m_NewTick = false;
	m_NewPredictedTick = false;

	// check if client info has to be resent
	if(m_LastSendInfo && Client()->State() == IClient::STATE_ONLINE && m_Snap.m_LocalClientID >= 0 && !m_pMenus->IsActive() && m_LastSendInfo+time_freq()*5 < time_get())
	{
		// resend if client info differs
		if(str_comp(g_Config.m_PlayerName, m_aClients[m_Snap.m_LocalClientID].m_aName) ||
			str_comp(g_Config.m_PlayerClan, m_aClients[m_Snap.m_LocalClientID].m_aClan) ||
			g_Config.m_PlayerCountry != m_aClients[m_Snap.m_LocalClientID].m_Country ||
			str_comp(g_Config.m_PlayerSkin, m_aClients[m_Snap.m_LocalClientID].m_aSkinName) ||
			(m_Snap.m_pGameInfoObj && !(m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS) &&	// no teamgame?
			(g_Config.m_PlayerUseCustomColor != m_aClients[m_Snap.m_LocalClientID].m_UseCustomColor ||
			g_Config.m_PlayerColorBody != m_aClients[m_Snap.m_LocalClientID].m_ColorBody ||
			g_Config.m_PlayerColorFeet != m_aClients[m_Snap.m_LocalClientID].m_ColorFeet)))
		{
			SendInfo(false);
		}
		m_LastSendInfo = 0;
	}
}
Beispiel #29
0
void CServerBrowser::Update(bool ForceResort)
{
	if(m_ServerdataLocked)
		return;
	int64 Timeout = time_freq();
	int64 Now = time_get();
	int Count;
	CServerEntry *pEntry, *pNext;

	// do server list requests
	if(m_NeedRefresh && !m_pMasterServer->IsRefreshing())
	{
		NETADDR Addr;
		CNetChunk Packet;
		int i = 0;

		m_NeedRefresh = 0;
		m_MasterServerCount = -1;
		mem_zero(&Packet, sizeof(Packet));
		Packet.m_ClientID = -1;
		Packet.m_Flags = NETSENDFLAG_CONNLESS;
		Packet.m_DataSize = sizeof(SERVERBROWSE_GETCOUNT);
		Packet.m_pData = SERVERBROWSE_GETCOUNT;

		for(i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
		{
			if(!m_pMasterServer->IsValid(i))
				continue;

			Addr = m_pMasterServer->GetAddr(i);
			m_pMasterServer->SetCount(i, -1);
			Packet.m_Address = Addr;
			m_pNetClient->Send(&Packet);
			if(g_Config.m_Debug)
			{
				dbg_msg("client_srvbrowse", "count-request sent to %d", i);
			}
		}
	}

	// check if all server counts arrived
	if(m_MasterServerCount == -1)
	{
		m_MasterServerCount = 0;
		for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
		{
			if(!m_pMasterServer->IsValid(i))
				continue;
			int Count = m_pMasterServer->GetCount(i);
			if(Count == -1)
			{
			/* ignore Server
				m_MasterServerCount = -1;
				return;
				// we don't have the required server information
				*/
			}
			else
				m_MasterServerCount += Count;
		}

		// request serverlist
		NETADDR Addr;
		CNetChunk Packet;
		mem_zero(&Packet, sizeof(Packet));
		Packet.m_ClientID = -1;
		Packet.m_Flags = NETSENDFLAG_CONNLESS;
		Packet.m_DataSize = sizeof(SERVERBROWSE_GETLIST);
		Packet.m_pData = SERVERBROWSE_GETLIST;

		for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
		{
			if(!m_pMasterServer->IsValid(i))
				continue;

			Addr = m_pMasterServer->GetAddr(i);
			Packet.m_Address = Addr;
			m_pNetClient->Send(&Packet);
		}
		if(g_Config.m_Debug)
		{
			dbg_msg("client_srvbrowse", "servercount: %d, requesting server list", m_MasterServerCount);
		}
		m_LastPacketTick = 0;
	}
	else if(m_MasterServerCount > -1)
	{
		m_MasterServerCount = 0;
		for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
			{
				if(!m_pMasterServer->IsValid(i))
					continue;
				int Count = m_pMasterServer->GetCount(i);
				if(Count == -1)
				{
				/* ignore Server
					m_MasterServerCount = -1;
					return;
					// we don't have the required server information
					*/
				}
				else
					m_MasterServerCount += Count;
			}
			//if(g_Config.m_Debug)
			//{
			//	dbg_msg("client_srvbrowse", "ServerCount2: %d", m_MasterServerCount);
			//}
	}
	if(m_MasterServerCount > m_NumRequests + m_LastPacketTick)
	{
		++m_LastPacketTick;
		return; // wait for more packets
	}
	pEntry = m_pFirstReqServer;
	Count = 0;
	while(1)
	{
		if(!pEntry) // no more entries
			break;

		if(pEntry->m_RequestTime && pEntry->m_RequestTime+Timeout < Now)
		{
			pEntry = pEntry->m_pNextReq;
			continue;
		}

		// no more than 10 concurrent requests
		if(Count >= m_CurrentMaxRequests)
			break;

		if(pEntry->m_RequestTime == 0)
		{
			if (pEntry->m_Is64)
				RequestImpl64(pEntry->m_Addr, pEntry);
			else
				RequestImpl(pEntry->m_Addr, pEntry);
		}

		Count++;
		pEntry = pEntry->m_pNextReq;
	}

	// no more current server requests
	if(m_pFirstReqServer && Count == 0 && m_CurrentMaxRequests > 1)
	{
		// reset old ones
		pEntry = m_pFirstReqServer;
		while(1)
		{
			if(!pEntry) // no more entries
				break;

			pEntry->m_RequestTime = 0;
			pEntry = pEntry->m_pNextReq;
		}

		// update max-requests
		m_CurrentMaxRequests /= 2;
		if(m_CurrentMaxRequests <= 3)
		{
			m_CurrentMaxRequests = 1;
			m_NeedRefresh = false;
		}
	}
	else if(Count == 0 && m_CurrentMaxRequests == 1) // we reached the limit, just release all left requests. If a server sends us a packet, a new request will be added automatically, so we can delete all
	{
		pEntry = m_pFirstReqServer;
		while(1)
		{
			if(!pEntry) // no more entries
				break;
			pNext = pEntry->m_pNextReq;
			RemoveRequest(pEntry); // release request
			pEntry = pNext;
		}
	}

	// check if we need to resort
	if(m_Sorthash != SortHash() || ForceResort)
		Sort();
}
Beispiel #30
0
void CServerBrowser::LoadCacheThread(void *pUser)
{
	CServerBrowser *pSelf = (CServerBrowser *)pUser;
	IStorageTW *pStorage = pSelf->Kernel()->RequestInterface<IStorageTW>();

	int64 StartTime = time_get();

	// clear out everything
	pSelf->m_ServerlistHeap.Reset();
	pSelf->m_NumServers = 0;
	pSelf->m_NumSortedServers = 0;
	mem_zero(pSelf->m_aServerlistIp, sizeof(pSelf->m_aServerlistIp));
	pSelf->m_pFirstReqServer = 0;
	pSelf->m_pLastReqServer = 0;
	pSelf->m_NumRequests = 0;
	pSelf->m_CurrentMaxRequests = g_Config.m_BrMaxRequests;
	pSelf->m_CurrentToken = (pSelf->m_CurrentToken+1)&0xff;
	pSelf->m_ServerlistType = IServerBrowser::TYPE_INTERNET;

	// open file
	IOHANDLE File = pStorage->OpenFile("tmp/cache/serverlist", IOFLAG_READ, IStorageTW::TYPE_ALL);
	if(!File)
	{
		dbg_msg("browser", "opening cache file failed.");
		pSelf->m_CacheExists = false;
		pSelf->m_ServerdataLocked = false;
		return;// false;
	}

	// get version
	{
		char v; io_read(File, &v, 1);
		if(g_Config.m_Debug)
			dbg_msg("browser", "loading serverlist from cache...");
		if(v != CACHE_VERSION)
			dbg_msg("cache", "file version doesn't match, we may fail! (%i != %i)", v, CACHE_VERSION);
	}

	// get number of servers
	int NumServers = 0;
	io_read(File, &NumServers, sizeof(NumServers));
	//dbg_msg("browser", "serverlist cache entries: %i", NumServers);

	mem_zero(pSelf->m_ppServerlist, pSelf->m_NumServerCapacity);

	// get length of array
	io_read(File, &pSelf->m_NumServerCapacity, sizeof(pSelf->m_NumServerCapacity));

	// get rid of current serverlist and create a new one
	mem_free(pSelf->m_ppServerlist);
	pSelf->m_ppServerlist = (CServerEntry **)mem_alloc(pSelf->m_NumServerCapacity*sizeof(CServerEntry*), 1);

	// read the data from the file into the serverlist
	CServerInfo *pServerInfos = (CServerInfo*)mem_alloc(sizeof(CServerInfo)*NumServers, 0);
	io_read(File, pServerInfos, sizeof(CServerInfo)*NumServers);
	io_close(File);

	for(int i = 0; i < NumServers; i++)
	{
		NETADDR Addr;
		net_addr_from_str(&Addr, pServerInfos[i].m_aAddress);
		//dbg_msg("browser", "loading %i %s %s", i, Info.m_aAddress, Info.m_aName);
		pSelf->Set(Addr, IServerBrowser::SET_TOKEN, pSelf->m_CurrentToken, &pServerInfos[i]);
	}
	mem_free(pServerInfos);

	if(g_Config.m_Debug)
		dbg_msg("browser", "successfully loaded serverlist cache with %i entries (total %i), took %.2fms", pSelf->m_NumServers, NumServers, ((time_get()-StartTime)*1000)/(float)time_freq()); // TODO: check if saving actually succeeded
	//m_NeedUpgrade = true; // disabled due to sending our ip out to the whole universe
	pSelf->m_ServerdataLocked = false;
	pSelf->Sort(true);
	return;// true;
}