Beispiel #1
0
void NProj::addLibrary(void) {
	NDataStream tmp;

	NDebug::print() << "Number of files: " << m_lib_files.count();
	NDebug::print() << "Library name: " << m_lib_name;
	if (m_lib_name == "" && m_lib_files.count() > 0) {
		throw NException("You provided source files for building the "
			"library but no library name", NException::TOOLS);
	}
	else {
		if (m_lib_name != "" && m_lib_files.count() == 0) {
			throw NException("You provided a library name but "
				"no source files for building it", 
				NException::TOOLS);
		
		}
		else { 
			if (m_lib_name == "" && m_lib_files.count() == 0) { 
				return;
			}
		}

	}

	tmp = "# Project library\n";
	tmp = tmp + "ADD_LIBRARY(\n"; 
	tmp = tmp + "\t" + m_lib_name + "\n";
	
	for (nuint64 i = 0; i < m_lib_files.size(); i++) {
		tmp = tmp + "\t" + m_lib_files.at(i) + "\n";
	}
	tmp = tmp + ")\n\n";

	m_output.write(tmp);
}
Beispiel #2
0
bool NProj::setModules(const NOpt<NProj> &opts) { 
	NString tmp;
	NList<NString> validModules;

	validModules.append("NBase");
	validModules.append("NEvents");
	validModules.append("NNetwork");
	validModules.append("NSecurity");
	validModules.append("NXml");
	validModules.append("NDBal");
	validModules.append("NMySQL");

	tmp = opts.getValues().at(0);
	addOpt(&m_modules, tmp);

	for (nuint64 i = 0; i < m_modules.size(); i++) {
		if (!validModules.contains(m_modules.at(i))) {
			NString msg;

			msg = msg + "Module " + m_modules.at(i) + " is not a "
				"valid module";
			throw NException(msg, NException::TOOLS);
		}
	}

	return true;
}
Beispiel #3
0
void Client::createClient()
{
  struct protoent *proto;
  struct sockaddr_in sin;

  if ((proto = getprotobyname("TCP")) == 0)
    throw NException("Error : getprotobyname failed");
  if ((_socket = socket(AF_INET, SOCK_STREAM, proto->p_proto)) == -1)
    throw NException("Error : socket failed");

  sin.sin_family = AF_INET;
  sin.sin_port = htons(_port);

  if ((sin.sin_addr.s_addr = inet_addr(_ip.c_str())) == INADDR_NONE)
    throw NException("Error : inet_addr failed");
  if (connect(_socket, (const struct sockaddr *)&sin, sizeof(sin)) == -1)
    throw NException("Error : connect failed");
}
Beispiel #4
0
void NSql::setPort(nint16 port) { 
	if (port == 0) { 
		NString msg = "Port number ";

		msg = msg + port + " is not valid";

		throw NException(msg, NException::DBAL);
	}

	m_port = port;
	NDebug::print() << "Setting the port to " << m_port;
}
Beispiel #5
0
bool Client::getAns()
{
  FD_ZERO(&_set);
  FD_SET(_socket, &_set);

  if (select(_socket + 1, &_set, NULL, NULL, NULL) == -1)
    throw NException("Error : select failed");
  if (FD_ISSET(_socket, &_set))
    if (handleServer() == false)
      return false;
  return true;
}
Beispiel #6
0
void NProj::addExecutable(void) {
	NDataStream tmp;

	NDebug::print() << "Number of files: " << m_exe_files.count();
	NDebug::print() << "Executable name: " << m_exe_name;
	if (m_exe_name == "" && m_exe_files.count() > 0) {
		throw NException("You provided source files for building the "
			"executable but no executable name", NException::TOOLS);
	}
	else {
		if (m_exe_name != "" && m_exe_files.count() == 0) {
			throw NException("You provided an executable name but "
				"no source files for building it", 
				NException::TOOLS);
		
		}
		else { 
			if (m_exe_name == "" && m_exe_files.count() == 0) { 
				return;
			}
		}
	}

	tmp = "# Project executable\n";
	tmp = tmp + "ADD_EXECUTABLE(\n"; 
	tmp = tmp + "\t" + m_exe_name + "\n";
	
	for (nuint64 i = 0; i < m_exe_files.size(); i++) {
		NDebug::print() << "Adding " << m_exe_files.at(i);

		tmp = tmp + "\t" + m_exe_files.at(i) + "\n";
		create_if_not_exists(m_exe_files.at(i), m_license ? NLGPL : "", 
			m_force);
	}
	tmp = tmp + ")\n\n";

	m_output.write(tmp);
}
Beispiel #7
0
void Client::writeToSocket(std::string const &buffer)
{
  int len = buffer.size();
  int len2;

  len2 = 0;
  if (_step == GAME_STEP)
    ++_nbCmd;
  std::string buff(buffer);

  if (!buff.empty() && buffer[buff.length() - 1] == '\n')
    buff.erase(buff.length() - 1);

  std::cout << "\033[1;34m[CLIENT] Sending message : " << buff << "\033[0m"
	    << std::endl;

  while (len2 < len)
    {
      if ((len2 += write(_socket, buffer.c_str() + len2, len)) == -1)
	throw NException("Error : write failed");
    }
  if (_step == GAME_STEP)
    {
      refreshTime();
      getAns();
      if (_messages.size() == 0 && _regroupMessage.size() > 3
	  && _reading == false)
	{
	  _reading = true;
	  readMessage(_regroupMessage);
	  _reading = false;
	  _regroupMessage.clear();
	}
      if (_messages.size() > 0 && _reading == false)
	{
	  std::cout << "READING" << std::endl;
	  _reading = true;
	  for (size_t i = 0; i < _messages.size() ; ++i)
	    readMessage(_messages[i]);
	  _messages.clear();
	  if (_regroupMessage.size() > 3)
	    readMessage(_regroupMessage);
	  _regroupMessage.clear();
	  std::cout << "CLEAR" << std::endl;
	  _reading = false;
	  std::cout << "STOP READING" << std::endl;
	  std::cout << "TIME: " << _time << std::endl;
	}
    }
}
Beispiel #8
0
int NProj::run(void) {
	if (NFile::exists("CMakeLists.txt") && !m_force) {
		throw NException("There's already a CMakeLists.txt file in this"
			" project. Remove it before running nproj", 
			NException::TOOLS);
	}

	m_output.setFileName("CMakeLists.txt");
	m_output.open(NIODevice::Truncate);	

	setupHeader();
	addModules();
	addExecutable();
	addLibrary();

	m_output.closeDevice();
	
	return 0;
}
Beispiel #9
0
	NBEWindow::NBEWindow(RenderInfo* ri, HINSTANCE h)
		:RendererWindow(h), m_renderInfo(ri)
	{
		registerClass(h);

		DWORD style, exStyle;
		RECT _windowRect = { 0, 0, LONG(ri->width), LONG(ri->height) };

		if (ri->fullScreen)
		{
			style = WS_POPUP;
			exStyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
			HDC screen = GetDC(0);
			_windowRect.right = GetDeviceCaps(screen, HORZRES);
			_windowRect.bottom = GetDeviceCaps(screen, VERTRES);
		}
		else
		{
			style = WS_OVERLAPPEDWINDOW;
			exStyle = WS_EX_APPWINDOW;
		}

		AdjustWindowRectEx(&_windowRect, style, false, exStyle);

		m_hwnd = CreateWindowEx(exStyle, ri->className, ri->title, style,
			CW_USEDEFAULT, CW_USEDEFAULT, (_windowRect.right - _windowRect.left),
			(_windowRect.bottom - _windowRect.top), NULL, NULL, h, NULL);


		ShowWindow(m_hwnd, SW_SHOWNORMAL);
		UpdateWindow(m_hwnd);



		if (!m_hwnd)
		{
			throw NException(CreateWindowError, String(TEXT("Create Window Error")));
		}


	}
Beispiel #10
0
bool Client::handleServer()
{
  static char buff[32768];
  int len;

  std::memset(buff, '\0', 32768);

  if ((len = read(_socket, buff, 32767)) <= 0) {
  
    if (close(_socket) == -1)
      std::cerr << "Error : close failed" << std::endl;

    throw NException("Error : read failed");
  }

  std::string buffer(buff);

  if (!buffer.empty() && buffer[buffer.length() - 1] == '\n')
    buffer.erase(buffer.length() - 1);
  _ans = buffer;

  std::cout << "\033[1;31m[SERVER] : " << buffer << "\033[0m" << std::endl;

  if (_step == GAME_STEP) {
    if (buffer == "mort")
      {
	std::cout << "You died" << std::endl;
	return false;
      }

  } else {
    checkCmd(buff);
    if (_step == Client::ERROR_STEP)
      return false;
  }

  checkAns();
  
  return true;
}