コード例 #1
0
ファイル: WiimoteReal.cpp プロジェクト: Huanglihan/dolphin
bool Wiimote::Read()
{
	Report rpt(MAX_PAYLOAD);
	auto const result = IORead(rpt.data());

	if (result > 0 && m_channel > 0)
	{
		if (SConfig::GetInstance().iBBDumpPort > 0 &&
		    m_index == WIIMOTE_BALANCE_BOARD)
		{
			static sf::UdpSocket Socket;
			Socket.send((char*)rpt.data(),
			            rpt.size(),
			            sf::IpAddress::LocalHost,
		                SConfig::GetInstance().iBBDumpPort);
		}

		// Add it to queue
		rpt.resize(result);
		m_read_reports.Push(std::move(rpt));
		return true;
	}
	else if (0 == result)
	{
		ERROR_LOG(WIIMOTE, "Wiimote::IORead failed. Disconnecting Wiimote %d.", m_index + 1);
		DisconnectInternal();
	}

	return false;
}
コード例 #2
0
ファイル: WiimoteReal.cpp プロジェクト: Huanglihan/dolphin
bool Wiimote::Write()
{
	if (!m_write_reports.Empty())
	{
		Report const& rpt = m_write_reports.Front();

		bool const is_speaker_data = rpt[1] == WM_WRITE_SPEAKER_DATA;

		if (!is_speaker_data || m_last_audio_report.GetTimeDifference() > 5)
		{
			if (SConfig::GetInstance().iBBDumpPort > 0 && m_index == WIIMOTE_BALANCE_BOARD)
			{
				static sf::UdpSocket Socket;
				Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost, SConfig::GetInstance().iBBDumpPort);
			}
			IOWrite(rpt.data(), rpt.size());

			if (is_speaker_data)
			{
				m_last_audio_report.Update();
			}

			m_write_reports.Pop();
			return true;
		}
	}

	return false;
}
コード例 #3
0
ファイル: i_net.cpp プロジェクト: JonnyPtn/SFML-DOOM
//
// PacketGet
//
void PacketGet(void)
{
    int			    i;
    sf::IpAddress	fromaddress;
    size_t			fromlen;
    doomdata_t		sw;
    unsigned short  fromport;

    fromlen = sizeof(fromaddress);
    auto c = insocket.receive(&sw, sizeof(sw), fromlen
        , fromaddress, fromport);
    if (c != sf::Socket::Status::Done)
    {
        //if we've received something on a blocking socket, but the status isn't done, something's gone awry
        if (insocket.isBlocking())
            I_Error("GetPacket failed, sf::Socket::Status: %s", c);
        doomcom->remotenode = -1;		// no packet
        return;
    }

    {
        static int first = 1;
        if (first)
            printf("len=%d:p=[0x%x 0x%x] \n", c, *(int*)&sw, *((int*)&sw + 1));
        first = 0;
    }

    // find remote node number
    for (i = 0; i<doomcom->numnodes; i++)
        if (fromaddress == sendaddress[i])
            break;

    if (i == doomcom->numnodes)
    {
        // packet is not from one of the players (new game broadcast)
        doomcom->remotenode = -1;		// no packet
        return;
    }

    doomcom->remotenode = i;			// good packet from a game player
    doomcom->datalength = static_cast<short>(fromlen);

    // byte swap
    netbuffer->checksum = ntohl(sw.checksum);
    netbuffer->player = sw.player;
    netbuffer->retransmitfrom = sw.retransmitfrom;
    netbuffer->starttic = sw.starttic;
    netbuffer->numtics = sw.numtics;

    for (fromlen = 0; fromlen< netbuffer->numtics; fromlen++)
    {
        netbuffer->cmds[fromlen].forwardmove = sw.cmds[fromlen].forwardmove;
        netbuffer->cmds[fromlen].sidemove = sw.cmds[fromlen].sidemove;
        netbuffer->cmds[fromlen].angleturn = ntohs(sw.cmds[fromlen].angleturn);
        netbuffer->cmds[fromlen].consistancy = ntohs(sw.cmds[fromlen].consistancy);
        netbuffer->cmds[fromlen].chatchar = sw.cmds[fromlen].chatchar;
        netbuffer->cmds[fromlen].buttons = sw.cmds[fromlen].buttons;
    }
}
コード例 #4
0
ファイル: i_net.cpp プロジェクト: JonnyPtn/SFML-DOOM
//
// PacketSend
//
void PacketSend(void)
{
    int		c;
    doomdata_t	sw;

    // byte swap
    sw.checksum = htonl(netbuffer->checksum);
    sw.player = netbuffer->player;
    sw.retransmitfrom = netbuffer->retransmitfrom;
    sw.starttic = netbuffer->starttic;
    sw.numtics = netbuffer->numtics;
    for (c = 0; c< netbuffer->numtics; c++)
    {
        sw.cmds[c].forwardmove = netbuffer->cmds[c].forwardmove;
        sw.cmds[c].sidemove = netbuffer->cmds[c].sidemove;
        sw.cmds[c].angleturn = htons(netbuffer->cmds[c].angleturn);
        sw.cmds[c].consistancy = htons(netbuffer->cmds[c].consistancy);
        sw.cmds[c].chatchar = netbuffer->cmds[c].chatchar;
        sw.cmds[c].buttons = netbuffer->cmds[c].buttons;
    }

    //printf ("sending %i\n",gametic);		
    c = (int)sendsocket.send( &sw, doomcom->datalength
        , sendaddress[doomcom->remotenode],
        DOOMPORT);

    //	if (c == -1)
    //		I_Error ("SendPacket error: %s",strerror(errno));
}
コード例 #5
0
ファイル: WiimoteReal.cpp プロジェクト: FLyrfors/dolphin
void Wiimote::Write()
{
  if (m_write_reports.Empty())
    return;

  Report const& rpt = m_write_reports.Front();

  if (SConfig::GetInstance().iBBDumpPort > 0 && m_index == WIIMOTE_BALANCE_BOARD)
  {
    static sf::UdpSocket Socket;
    Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost,
                SConfig::GetInstance().iBBDumpPort);
  }
  IOWrite(rpt.data(), rpt.size());

  m_write_reports.Pop();

  if (!m_write_reports.Empty())
    IOWakeup();
}
コード例 #6
0
void Connection::send(sf::UdpSocket &socket, sf::Packet &packet) {
  if (socket.send(packet, address, port) != sf::Socket::Done) {
    logger->log("failed to send a package", Logger::Level::Error);
  }
}
コード例 #7
0
ファイル: i_net.cpp プロジェクト: JonnyPtn/SFML-DOOM
//
// I_InitNetwork
//
void I_InitNetwork(void)
{
    int			i;
    int			p;

    doomcom = static_cast<doomcom_t*>(malloc(sizeof(*doomcom)));
    memset(doomcom, 0, sizeof(*doomcom));

    // set up for network
    i = CmdParameters::M_CheckParm("-dup");
    if (i && i< CmdParameters::myargc - 1)
    {
        doomcom->ticdup = CmdParameters::myargv[i + 1][0] - '0';
        if (doomcom->ticdup < 1)
            doomcom->ticdup = 1;
        if (doomcom->ticdup > 9)
            doomcom->ticdup = 9;
    }
    else
        doomcom->ticdup = 1;

    if (CmdParameters::M_CheckParm("-extratic"))
        doomcom->extratics = 1;
    else
        doomcom->extratics = 0;

    p = CmdParameters::M_CheckParm("-port");
    if (p && p<CmdParameters::myargc - 1)
    {
        DOOMPORT = atoi(CmdParameters::myargv[p + 1].c_str());
        printf("using alternate port %i\n", DOOMPORT);
    }

    // parse network game options,
    //  -net <consoleplayer> <host> <host> ...
    i = CmdParameters::M_CheckParm("-net");
    if (!i)
    {
        // single player game
        netgame = false;
        doomcom->id = DOOMCOM_ID;
        doomcom->numplayers = doomcom->numnodes = 1;
        doomcom->deathmatch = false;
        doomcom->consoleplayer = 0;
        return;
    }

    netsend = PacketSend;
    netget = PacketGet;
    netgame = true;

    // parse player number and host list
    doomcom->consoleplayer = CmdParameters::myargv[i + 1][0] - '1';

    doomcom->numnodes = 1;	// this node for sure

    i++;
    while (++i < CmdParameters::myargc && CmdParameters::myargv[i][0] != '-')
    {
        sendaddress[doomcom->numnodes] = CmdParameters::myargv[i];
        doomcom->numnodes++;
    }

    doomcom->id = DOOMCOM_ID;
    doomcom->numplayers = doomcom->numnodes;

    // build message to receive
    insocket.bind(DOOMPORT);
    insocket.setBlocking(false);
    sendsocket.setBlocking(false);
}