Пример #1
0
//====================================
void loadCurrentProj()
//====================================
{
  int x,res;
  char syscom[120],temp[200];

  g_warning = S_NO;
  putMsg(1,"Loading ...");
  res = loadSketch(confSketchFile);
  if(res == 0)
  {
    if(confSteps < 0) confSteps = 100;
    if(confSteps > MAX_STEP) confSteps = MAX_STEP-1;
    sprintf(syscom,"cd servuino;./servuino %d %d;",confSteps,g_scenSource);
    x=system(syscom);
    initSim();
    resetSim();
    readSimulation();
    readSketchInfo();
    setRange(confBoardType);
    init(confWinMode);
    saveConfig(currentConf);
    unoInfo();
    sprintf(temp,"Sketch load ready: %s",confSketchFile);
    putMsg(msg_h-2,temp);
  }
}
Пример #2
0
/* add a client into our array of clients */
Client *add_client(TCPsocket sock, char *name)
{
	fix_nick(name);
	if(!strlen(name))
	{
		putMsg(sock,"Invalid Nickname...bye bye!");
		SDLNet_TCP_Close(sock);
		return(NULL);
	}
	if(!unique_nick(name))
	{
		putMsg(sock,"Duplicate Nickname...bye bye!");
		SDLNet_TCP_Close(sock);
		return(NULL);
	}
	clients=(Client*)realloc(clients, (num_clients+1)*sizeof(Client));
	clients[num_clients].name=name;
	clients[num_clients].sock=sock;
	num_clients++;
	/* server side info */
	printf("--> %s\n",name);
	/* inform all clients, including the new one, of the joined user */
	send_all(mformat("ss","--> ",name));
	return(&clients[num_clients-1]);
}
Пример #3
0
  StateResult ActionPutInto::doPreBeginWorkNVI(GameState& gameState, Systems::Manager& systems, json& arguments)
  {
    std::string message;
    auto subject = getSubject();
    auto object = getObject();
    auto container = getTargetThing();
    auto& narrator = systems.narrator();

    // Verify that the Action has an object.
    if (object == EntityId::Void)
    {
      return StateResult::Failure();
    }

    // Check that the entity and container aren't the same entity.
    if (object == container)
    {
      if (gameState.components().globals.player() == subject)
      {
        message = narrator.makeTr("YOU_TRY_TO_STORE_THE_FOO_INSIDE_ITSELF_HUMOROUS", arguments);
      }
      else
      {
        message = narrator.makeTr("YOU_TRY_TO_STORE_THE_FOO_INSIDE_ITSELF_INVALID", arguments);
        CLOG(WARNING, "Action") << "NPC tried to store a container in itself!?";
      }

      return StateResult::Failure();
    }

    // Check that the container actually IS a container.
    if (COMPONENTS.inventory.valueOrDefault(container).maxSize() == 0)
    {
      printMessageTry(systems, arguments);
      putMsg(narrator.makeTr("THE_TARGET_IS_NOT_A_CONTAINER", arguments));
      return StateResult::Failure();
    }

    // Check that the entity's location isn't already the container.
    if (COMPONENTS.position[object].parent() == container)
    {
      printMessageTry(systems, arguments);
      putMsg(narrator.makeTr("THE_FOO_IS_ALREADY_IN_THE_TARGET", arguments));
      return StateResult::Failure();
    }

    // Check that the container is within reach.
    if (!systems.geometry()->firstCanReachSecond(subject, container))
    {
      printMessageTry(systems, arguments);
      putMsg(narrator.makeTr("THE_TARGET_IS_OUT_OF_REACH", arguments));
      return StateResult::Failure();
    }

    return StateResult::Success();
  }
Пример #4
0
  StateResult ActionWield::doPreBeginWorkNVI(GameState& gameState, Systems::Manager& systems, json& arguments)
  {
    std::string message;
    auto subject = getSubject();
    auto object = getObject();
    auto& components = gameState.components();
    auto& narrator = systems.narrator();

    /// @todo Support wielding in other prehensile limb(s). This will also include
    ///       shifting an already-wielded weapon to another hand.
    m_bodyLocation = { BodyPart::Hand, 0 };
    EntityId currentlyWielded = components.bodyparts[subject].getWieldedEntity(m_bodyLocation);

    std::string bodypartDesc = narrator.getBodypartDescription(subject, m_bodyLocation);

    // If it is us, or it is what is already being wielded, it means to unwield whatever is wielded.
    if ((object == subject) || (object == currentlyWielded) || (object == EntityId::Void))
    {
      std::unique_ptr<Action> unwieldAction(NEW ActionUnwield(subject));
      systems.director().queueEntityAction(subject, std::move(unwieldAction));

      return StateResult::Failure();
    }
    else if (currentlyWielded != EntityId::Void)
    {
      arguments["bodypart"] = bodypartDesc;
      putMsg(narrator.makeTr("YOU_MUST_UNWIELD_FIRST", arguments));
      return StateResult::Failure();
    }

    return StateResult::Success();
  }
Пример #5
0
  StateResult ActionPutInto::doBeginWorkNVI(GameState& gameState, Systems::Manager& systems, json& arguments)
  {
    /// @todo Handle putting a certain quantity of an item.
    StateResult result = StateResult::Failure();
    std::string message;
    auto subject = getSubject();
    auto object = getObject();
    auto container = getTargetThing();
    auto& lua = gameState.lua();
    auto& narrator = systems.narrator();

    if (lua.doSubjectActionObject(subject, *this, container))
    {
      printMessageDo(systems, arguments);

      if (systems.geometry().moveEntityInto(object, container))
      {
        /// @todo Figure out action time.
        result = StateResult::Success();
      }
      else
      {
        arguments["preposition"] = tr("PREPOSITION_INTO");
        putMsg(narrator.makeTr("YOU_CANT_VERB_FOO_PREPOSITION_TARGET_UNKNOWN", arguments));

        CLOG(ERROR, "Action") << "Could not move Entity into Container even though beObjectOf returned Success";
      }
    }

    return result;
  }
Пример #6
0
int UnistorHandler4Trans::open (void * arg){
    m_bAuth = false;
    int ret = CwxAppHandler4Channel::open(arg);
    if (0 == ret){
        UnistorTss* tss = (UnistorTss*)CwxTss::instance();
        ///发送认证消息
        CwxMsgBlock* block = NULL;
        if (UNISTOR_ERR_SUCCESS != UnistorPoco::packRecvAuth(tss->m_pWriter,
            block,
            0,
            m_pApp->getConfig().getRecv().getUser().length()?m_pApp->getConfig().getRecv().getUser().c_str():"",
            m_pApp->getConfig().getRecv().getPasswd().length()?m_pApp->getConfig().getRecv().getPasswd().c_str():"",
            tss->m_szBuf2K))
        {
            CWX_ERROR(("Failure to pack recv auth package, err=%s", tss->m_szBuf2K));
            ret = channel()->removeHandler(this);
            if (0 != ret){
                CWX_ERROR(("Failure to remove handler from channel"));
            }
            return -1;
        }
        (*m_handlers)[m_uiConnId] = this;
        block->send_ctrl().setMsgAttr(CwxMsgSendCtrl::NONE);
        ///发送消息
        putMsg(block);
    }
    return 0;
}
Пример #7
0
void CwxEchoChannelEventHandler::replyMessage()
{
    ///设置echo回复的消息类型,为请求的消息类型+1
    m_recvMsgData->event().getMsgHeader().setMsgType(m_recvMsgData->event().getMsgHeader().getMsgType() + 1);
    ///设置echo回复的数据包长度
    m_recvMsgData->event().getMsgHeader().setDataLen(m_recvMsgData->length());
    ///创建回复的数据包
    CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(m_recvMsgData->length() + CwxMsgHead::MSG_HEAD_LEN);
    ///拷贝数据包的包头
    memcpy(pBlock->wr_ptr(), m_recvMsgData->event().getMsgHeader().toNet(), CwxMsgHead::MSG_HEAD_LEN);
    ///滑动block的写指针
    pBlock->wr_ptr(CwxMsgHead::MSG_HEAD_LEN);
    ///拷贝数据包的数据
    memcpy(pBlock->wr_ptr(), m_recvMsgData->rd_ptr(), m_recvMsgData->length());
    ///滑动block的写指针
    pBlock->wr_ptr(m_recvMsgData->length());
    if (!putMsg(pBlock))
    {
        CWX_ERROR(("Failure to put message"));
        CwxMsgBlockAlloc::free(pBlock);
    }
    m_ullMsgNum ++;
    if (m_ullMsgNum && !(m_ullMsgNum%10000))
    {
        char szBuf[64];
        CwxCommon::toString(m_ullMsgNum, szBuf, 10);
        CWX_INFO(("Recv echo message num:%s", szBuf));
    }


}
Пример #8
0
///发送topic状态表
int CwxMqInnerDispHandler::syncTopicState(CwxMqTss* pTss) {
  if (m_syncSession->m_topicIsChanged) {
    map<string, CWX_UINT8> topicState;
    map<string, CwxBinlogMgrCursor*>::iterator iter = m_syncSession->m_binlogCursor.begin();
    while (iter != m_syncSession->m_binlogCursor.end()) {
      topicState.insert(pair<string, CWX_UINT8>(iter->first, iter->second->m_binlogMgr->getZkTopicState()));
      CWX_DEBUG(("sync topic:%s, state:%d", iter->first.c_str(), iter->second->m_binlogMgr->getZkTopicState()));
      iter++;
    }
    CwxMsgBlock* pBlock;
    int ret = CwxMqPoco::packTopicState(pTss->m_pWriter, pTss->m_pItemWriter, pBlock, 0, topicState, pTss->m_szBuf2K);
    if (ret != CWX_MQ_ERR_SUCCESS) {
      CWX_ERROR(("Failure to pack topicState err:%s", pTss->m_szBuf2K));
      return -1;
    }
    ///根据svr类型,发送数据包
    pBlock->send_ctrl().setConnId(CWX_APP_INVALID_CONN_ID);
    pBlock->send_ctrl().setSvrId(CwxMqApp::SVR_TYPE_INNER_DISP);
    pBlock->send_ctrl().setHostId(0);
    pBlock->send_ctrl().setMsgAttr(CwxMsgSendCtrl::NONE);
    if (!putMsg(pBlock)) {
      CwxCommon::snprintf(pTss->m_szBuf2K, 2047, "Failure to send topicState msg.");
      CWX_ERROR((pTss->m_szBuf2K));
      CwxMsgBlockAlloc::free(pBlock);
      return -1;
    }
    m_syncSession->m_topicIsChanged = false;
  }
  return 0;
}
Пример #9
0
/**
@brief Handler的redo事件,在每次dispatch时执行。
@return -1:处理失败,会调用close(); 0:处理成功
*/
int CwxMqInnerDispHandler::onRedo() {
  ///发送下一条binlog
  int iState = syncSendBinLog(m_tss);
  if (-1 == iState) {
    CWX_ERROR(("%s, from:%s:%u", m_tss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
    CwxMsgBlock* msg = NULL;
    if (CWX_MQ_ERR_ERROR != CwxMqPoco::packSyncErr(m_tss->m_pWriter,
      msg,
      m_header.getTaskId(),
      CWX_MQ_ERR_ERROR,
      m_tss->m_szBuf2K,
      m_tss->m_szBuf2K))
    {
      CWX_ERROR(("Failure to pack sync data reply, err=%s, from:%s:%u", m_tss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      return -1;
    }
    msg->send_ctrl().setMsgAttr(CwxMsgSendCtrl::CLOSE_NOTICE);
    if (!putMsg(msg)) {
      CwxMsgBlockAlloc::free(msg);
      CWX_ERROR(("Failure push msg to send queue. from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      return -1;
    }
  } else if (0 == iState) { ///产生continue的消息
    channel()->regRedoHander(this);
  }
  return 0;
}
Пример #10
0
  StateResult ActionWield::doFinishWorkNVI(GameState& gameState, Systems::Manager& systems, json& arguments)
  {
    auto subject = getSubject();
    auto object = getObject();
    auto& components = gameState.components();
    auto& narrator = systems.narrator();

    std::string bodypart_desc = narrator.getBodypartDescription(subject, m_bodyLocation);

    COMPONENTS.bodyparts[subject].wieldEntity(object, m_bodyLocation);
    arguments["your_bodypart"] = narrator.getPossessiveString(subject, bodypart_desc);
    putMsg(narrator.makeTr("YOU_ARE_NOW_WIELDING_THE_FOO", arguments));

    return StateResult::Success();
  }
Пример #11
0
void main()
{
	FILE *forward = fopen("forward.bin","wb+");
	FILE *backward = fopen("backward.bin","wb+");
	while(1)
	{
	struct msg Msg;
	printf("\t\t\t\t=>:");fflush(stdin);
	gets(Msg.text);
	if(cmp(Msg.text,"exit") == 0)
		exit(0);
	putMsg(Msg,forward);
	printf("==>%s",getMsg(backward));
	}

}
Пример #12
0
/* send a buffer to all clients */
void send_all(const char *buf)
{
	int cindex;

	if(!buf || !num_clients)
		return;
	cindex=0;
	while(cindex<num_clients)
	{
		/* putMsg is in tcputil.h, it sends a buffer over a socket */
		/* with error checking */
		if(putMsg(clients[cindex].sock,buf))
			cindex++;
		else
			remove_client(cindex);
	}
}
Пример #13
0
//====================================
void runMode(int stop)
//====================================
{
  int ch,x,step,tmp,res=0,a=0,b=0,ir,ok=0,n=0;
  char tempName[80],syscom[120],temp[80];
  char command[40][40];

  strcpy(tempName,"help.txt");

  s_mode = S_RUN;


  if(stop > 1)
    {
      if(stop > g_steps)stop = g_steps;
      //if(stop > currentStep)
	runAll(stop);
      return;
    }

  putMsg(3,"Run Mode. Press h for help.");

  while(1)  
    {
      anyErrors();
      if(g_silent==S_NO )mvwprintw(uno,board_h-2,1,"R%1d>",confWinMode);
      if(g_silent==S_YES)mvwprintw(uno,board_h-2,1,"R%1d<",confWinMode);
      unoInfo();

      if(g_debug == 1) 
	readFile(confSketchFile,g_lineSketch[currentStep]);


      ch = getchar();

      if (ch=='q')
	{
	  return;
	}

      if (ch=='h')
        {
          readMsg(fileInfoRun);
        }
      else if (ch=='c')
        {
          readMsg(currentConf);
        }
      else if (ch=='d')
        {
          readMsg(fileServTime);
        }
      else if(ch=='y' ) // scenario
	{
	  readMsg(fileServScen);
	}
      else if (ch=='x')
	{
	  readMsg(fileServScenario);
	}
      else if (ch=='G')
	{
	  runAll(g_steps);
	}
      else if (ch=='l')
	{
	  showLoops();
	}
      else if (ch=='s')
	{
	  g_debug++;
	  if(g_debug > 1)g_debug = 0;
	}
      else if (ch=='w')
	{
	  confWinMode++;
	  if(confWinMode > WIN_MODES)confWinMode = 0;
          init(confWinMode);
	  mvwprintw(uno,board_h-2,1,"R%1d>",confWinMode);
	  unoInfo();
	}
      else if (ch=='a')
	{
          goStep(1);
	}
      else if (ch=='r')
	{
          goStep(loopStep[currentLoop+1]);
	}
      else if (ch=='o')
	{
          goStep(loopStep[currentLoop]);
	}
      else if (ch=='p')
	{
          goStep(loopStep[currentLoop-1]);
	}
      else if (ch=='z')
	{
          goStep(g_steps);
	}
      else if (ch=='k')
	{
	  resetSim();
	  init(confWinMode);
	  unoInfo();
	  mvwprintw(uno,board_h-2,1,"R%1d>",confWinMode);
	  show(uno);
	}
      else if (ch=='f')// Up Arrow 
	{
	  goStep(currentStep+1);
	}
      else if (ch=='b')// Down Arrow
	{
	  goStep(currentStep-1);
	}
      else if (ch=='R') // Right Arrow
	{
	  runLoop(S_FORWARD);
	}
      else if (ch=='P') // Left Arrow
	{
	  runLoop(S_BACKWARD);
	}
      else if (ch=='t')
	{
	  runNextRead();
	}
      else if (ch=='j')
	{
	  runPrevRead();
	}
      else if (ch=='i') 
	{
          step = currentStep;
	  sprintf(temp,"(Step:%d) Enter: d/a pin value (q - cancel)",step);
          putMsg(2,temp);
	  wgetstr(uno,temp);
	  n = tokCommand(command,temp);
      
	  if(strstr(command[0],"q") == NULL && n == 3)
	    {
	      g_pinNo = atoi(command[1]);
	      x = atoi(command[2]);
	      printf("%s %d %d",command[0],g_pinNo,x);
	      if(strstr(command[0],"a"))
		{
		  ok = ok + checkRange(S_OK,"anapin",g_pinNo);
		  ok = ok + checkRange(S_OK,"anaval",x);
		  g_pinType = ANA;
		}
	      if(strstr(command[0],"d"))
		{
		  ok = ok + checkRange(S_OK,"digpin",g_pinNo);
		  ok = ok + checkRange(S_OK,"digval",x);
		  g_pinType = DIG;
		}
	      if(ok == S_OK)
		{ 
		  g_scenSource = 1;
		  // steps, source, pintype, pinno, pinvalue, pinstep
		  sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,x,currentStep,S_ADD);
		  tmp=system(syscom);
		  initSim();
		  readSketchInfo();
		  readSimulation();
		  goStep(currentStep);
		  readMsg(fileServScen);
		}
	    }
	  else
	    putMsg(2,"Cancelled!");
	}
      else if (ch=='v') 
	{
          step = currentStep ;
	  sprintf(temp," Enter value to be read at step %d (q - cancel)",step);
          putMsg(2,temp);
	  res = analyzeEvent(simulation[step]);
          if(res > 0)
	    {
	      wgetstr(uno,temp);

	      if(strstr(temp,"q") == NULL)
		{
		  x = atoi(temp); 
		  ok = S_OK;
		  if(res == ANA)ok = ok + checkRange(S_OK,"anaval",x);
		  if(res == DIG)ok = ok + checkRange(S_OK,"digval",x);
		  if(ok == S_OK)
		    {         
		      g_scenSource = 1;
		      // steps, source, pintype, pinno, pinvalue, pinstep
		      sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,x,currentStep,S_ADD);
		      tmp=system(syscom);
		      initSim();
		      readSketchInfo();
		      readSimulation();
		      goStep(currentStep);
		      readMsg(fileServScen);
		    }
		}
	      else
		putMsg(2,"Cancelled!");
	    }
	  else
	    putMsg(2,"Next step is not a Read event");
	}
      else
	{
	  sprintf(temp,"Unknown command: %c",ch);
	  putMsg(msg_h-2,temp);
	}
    }
  return;
}
Пример #14
0
//====================================
void openCommand()
//====================================
{
  struct stat st;
  int ch,nsteps=1000,x,i,n,stop=0,loop,projNo = 0,ok=0,tmp;
  char *p,str[120],sstr[20],fileName[120],temp[120],syscom[120];
  char command[40][40];

  s_mode = S_ADMIN;
  g_silent = 0;

  readMsg(gplFile);

  while(strstr(str,"ex") == NULL)
    {
      anyErrors();
      unoInfo();

      wmove(uno,board_h-2,1);
      wprintw(uno,"                                                  ");
      if(g_silent==S_NO )mvwprintw(uno,board_h-2,1,"A%1d>",confWinMode);
      if(g_silent==S_YES)mvwprintw(uno,board_h-2,1,"A%1d<",confWinMode);

      strcpy(command[0],"");

      wgetstr(uno,str);

      n = tokCommand(command,str);

      strcpy(sstr,command[0]);

      p = str;

      projNo = atoi(sstr);

      if(strstr(sstr,"gpl"))
        {
          readMsg(gplFile);
        }
      else if(strstr(sstr,"err"))
        {
          readMsg(fileTemp);
        }
      else if(strstr(sstr,"run"))
	{
	  stop = 1;
          if(n == 2)stop = atoi(command[1]);
	  stop = checkRange(HEAL,"step",stop);

	  runMode(stop);
          if(stop==0)putMsg(2,"Back in Admin Mode!");
	}
      else if(strstr(sstr,"res")) // reset simulation
	{
	  resetSim();
	  init(confWinMode);
	  unoInfo();
	  readMsg(currentConf);
	}
      else if(strstr(sstr,"help")) //
	{
	  strcpy(fileName,fileInfoAdmin);
	  readMsg(fileName);
	}
      else if(strstr(sstr,"rem")) //
	{
	  if(n == 4)
	    {
	      if(strstr(command[1],"a"))g_pinType = ANA;
	      if(strstr(command[1],"d"))g_pinType = DIG;
	      g_pinNo   = atoi(command[2]);
	      g_pinStep = atoi(command[3]);
	      if(g_pinType == ANA)
		ok = checkRange(S_OK,"anapin",g_pinNo);
	      if(g_pinType == DIG)
		ok = checkRange(S_OK,"digpin",g_pinNo);
	      if(ok == S_OK)
		{
		  g_scenSource = 1;
		  sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,0,g_pinStep,S_DELETE);
		  //putMsg(2,syscom);
		  tmp=system(syscom);
		  initSim();
		  readSketchInfo();
		  readSimulation();
		  runStep(S_FORWARD);
		  readMsg(fileServScen);
		}
	      else
		putMsg(2,"Wrong pin number or pin type!");
	    }
	  else
	    putMsg(2,"Syntax: rem <a or d> <pin> <step>");
	}
      else if(strstr(sstr,"add")) //
	{
	  if(n == 5)
	    {
	      if(strstr(command[1],"a"))g_pinType = ANA;
	      if(strstr(command[1],"d"))g_pinType = DIG;

	      g_pinNo    = atoi(command[2]);
	      g_pinStep  = atoi(command[3]);
	      g_pinValue = atoi(command[4]);

	      ok = S_OK;
	      if(g_pinType == ANA)
		ok = checkRange(S_OK,"anapin",g_pinNo);
	      if(g_pinType == DIG)
		ok = checkRange(S_OK,"digpin",g_pinNo);

	      ok = ok + checkRange(S_OK,"step",g_pinStep);

	      if(ok == S_OK)
		{
		  g_scenSource = 1;
		  sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,g_pinValue,g_pinStep,S_ADD);
		  tmp=system(syscom);
		  initSim();
		  readSketchInfo();
		  readSimulation();
		  runStep(S_FORWARD);
		  readMsg(fileServScen);
		}
	    }
	  else
	    putMsg(2,"Syntax: add <a or d> <pin> <step> <value>");
	}
      else if(strstr(sstr,"info"))
	{
	  if(n == 2)
	    {
	      if(strstr(command[1],"conf"))
		{
		  readMsg(fileDefault);
		}
	      else if(strstr(command[1],"err"))
		{
		  readMsg(fileServError);
		}
	      else if(strstr(command[1],"g++"))
		{
		  readMsg(fileServComp);
		}
	      else if(strstr(command[1],"help"))
		{
		  readMsg(fileInfoAdmin);
		}
	      else if(strstr(command[1],"loop")) 
		{
		  showLoops();
		}
	      else if(strstr(command[1],"scen")) // scenario
		{
		  readMsg(fileServScen);
		}
	    }
	  else
	    {
	      readMsg(fileInfoAdmin);
	    }
	}

      else if(strstr(sstr,"proj"))
	{
	  if(n == 2)
	    {
	      strcpy(currentConf,command[1]);
	      strcat(currentConf,".conf");
	      readConfig(currentConf);
              g_warning = S_YES;
	      unoInfo();
	    }
	  readMsg(currentConf);
	}
      else if(strstr(sstr,"list"))
	{
	  readMsg(fileProjList);	
	}
      else if(strstr(sstr,"sketch"))
	{
	  if(n == 2)
	    {
	      if(strstr(command[1],"conf"))
		{
		  readMsg(confSketchFile);
		}
	      else if(strstr(command[1],"work"))
		{
		  readMsg(fileServSketch);
		}
	    }
	  else
	    readMsg(fileServSketch);	
	}
      else if(strstr(sstr,"conf"))
	{
	  if(n == 3)
	    {
	      if(strstr(command[1],"sim"))
		{
		  confSteps = atoi(command[2]);	
		}
	      else if(strstr(command[1],"win"))
		{
		  confWinMode = atoi(command[2]);
		  if(confWinMode > WIN_MODES)confWinMode = 0;
		  init(confWinMode);
		  unoInfo();
		}
	      else if(strstr(command[1],"sketch"))
		{
		  strcpy(temp,command[2]);
		  if(stat(temp,&st) == 0)
		    {
		      strcpy(confSketchFile,command[2]);
		    }
		  else
		    {
		      sprintf(temp,"Sketch not found: %s",command[2]);// Issue 16
		      putMsg(msg_h-2,temp);
		    }
		}
	      saveConfig(currentConf);
	    }
	  readMsg(currentConf); 
	}
      
      
      else if(strstr(sstr,"sav")) //save config
	{
	  if(n == 2)
	    {
	      strcpy(currentConf,command[1]);
	      strcat(currentConf,".conf");
              
	    }
	  saveConfig(currentConf);
	  readMsg(currentConf);
	  sprintf(syscom,"ls *.conf > %s;",fileProjList);
	  x=system(syscom);
	}
      else if(strstr(sstr,"del")) //delete config
	{
	  if(n == 2)
	    {
	      strcpy(currentConf,command[1]);
	      strcat(currentConf,".conf");
              
	    }
          if(strstr(currentConf,"default") == NULL)
	    {
	      sprintf(syscom,"rm %s;",currentConf);
	      x=system(syscom);
	      sprintf(syscom,"ls *.conf > %s;",fileProjList);
	      x=system(syscom);
	      readMsg(fileProjList);
	      strcpy(currentConf,fileDefault);
	    }	
	}
      else if(strstr(sstr,"win")) //windows layout
        {
          if(n == 2)
	    {
              confWinMode = atoi(command[1]);
              if(confWinMode > WIN_MODES)confWinMode = 0;
              init(confWinMode);
              unoInfo();
	    }
        }
      else if(strstr(sstr,"loop"))
	{
          if(n == 2)loop = atoi(command[1]);
	  loop = checkRange(HEAL,"loop",loop);
	  runLoops(loop);
	}
      else if(strstr(sstr,"clear"))
	{
	  sprintf(syscom,"rm servuino/sketch.ino;rm servuino/data.su;rm servuino/data.scen;");
	  x=system(syscom);
	}
      else if(strstr(sstr,"load"))
	{
          if(n == 2)
	    {
	      confSteps = atoi(command[1]);
	    }
          g_scenSource = 0;
	  loadCurrentProj();
	}
      else if(projNo > 0 && projNo < 10)
        {
	  selectProj(projNo,currentConf);
	  readConfig(currentConf);
	  g_warning = S_YES;
	  unoInfo();
	  readMsg(currentConf);   
        }
      else if(strstr(sstr,"data"))
	{
	  if(n == 2)
	    {
	      if(strstr(command[1],"ard"))
		{
		  readMsg(fileServArduino);
		}
	      else if(strstr(command[1],"cus"))
		{
		  readMsg(fileServCustom);
		}
	      else if(strstr(command[1],"cod"))
		{
		  readMsg(fileServCode);
		}
	      else if(strstr(command[1],"err"))
		{
		  readMsg(fileServError);
		}
	      else if(strstr(command[1],"sce"))
		{
		  readMsg(fileServScen);
		}
	    }
	  else
	    readMsg(fileServArduino);
	}
      else 
	{
	  putMsg(msg_h-2,"Unknown Admin command");
	}
    }
}
Пример #15
0
int CwxMqInnerDispHandler::recvReport(CwxMqTss* pTss) {
  int iRet = 0;
  CWX_UINT64 ullSid = 0;
  CWX_UINT32 uiChunk = 0;
  bool bZip = false;
  CwxMsgBlock* msg = NULL;
  do {
    if (!m_recvMsgData) {
      strcpy(pTss->m_szBuf2K, "No data.");
      CWX_ERROR(("Report package is empty, from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      iRet = CWX_MQ_ERR_ERROR;
      break;
    }
    ///禁止重复report sid。若cunsor存在,表示已经报告过一次
    if (m_syncSession) {
      iRet = CWX_MQ_ERR_ERROR;
      CwxCommon::snprintf(pTss->m_szBuf2K, 2048,
          "Can't report sync sid duplicate.");
      CWX_ERROR(("Report is duplicate, from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    ///若是同步sid的报告消息,则获取报告sid
    iRet = CwxMqPoco::parseInnerReportData(pTss->m_pReader,
        m_recvMsgData,
        ullSid,
        uiChunk,
        bZip,
        pTss->m_szBuf2K);
    if (CWX_MQ_ERR_SUCCESS != iRet) {
      CWX_ERROR(("Failure to parse report msg, err=%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    CWX_INFO(("Report info :%s:%u, sid=%s, chunk=%u, zip=%s", m_strPeerHost.c_str(), m_unPeerPort, CwxCommon::toString(ullSid, pTss->m_szBuf2K, 10),
        uiChunk, bZip?"yes":"no"));
    m_syncSession = new CwxMqInnerDispSession(m_pApp);
    m_syncSession->m_strHost = m_strPeerHost;
    m_syncSession->m_uiChunk = uiChunk;
    m_syncSession->m_bZip = bZip;
    if (m_syncSession->m_uiChunk) {
      if (m_syncSession->m_uiChunk > CwxMqConfigCmn::MAX_CHUNK_SIZE_KB)
        m_syncSession->m_uiChunk = CwxMqConfigCmn::MAX_CHUNK_SIZE_KB;
      if (m_syncSession->m_uiChunk < CwxMqConfigCmn::MIN_CHUNK_SIZE_KB)
        m_syncSession->m_uiChunk = CwxMqConfigCmn::MIN_CHUNK_SIZE_KB;
      m_syncSession->m_uiChunk *= 1024;
    }
    m_syncSession->reformSessionId();
    ///将session加到session的map
    while (m_sessions.find(m_syncSession->m_ullSessionId) != m_sessions.end()) {
      m_syncSession->reformSessionId();
    }
    m_sessions[m_syncSession->m_ullSessionId] = m_syncSession;
    m_ullSessionId = m_syncSession->m_ullSessionId;
    m_syncSession->addConn(this);
    if (0 != m_syncSession->init()) {
      CWX_ERROR(("Failure to init session min heap."));
      break;
    }
    ///回复iRet的值
    iRet = CWX_MQ_ERR_SUCCESS;
    ///创建binlog的读取cursor
    list<string> topics;
    m_pApp->getTopicMgr()->getAllTopics(topics);
    for(list<string>::iterator iter = topics.begin(); iter != topics.end(); iter++) {
      CwxBinLogMgr* binlogMgr = m_pApp->getTopicMgr()->getBinlogMgrByTopic(*iter);
      if (!binlogMgr) { ///binlogMgr被删除
        CWX_ERROR(("Failure to get BinloMgr topic:%s", iter->c_str()));
        continue;
      }
      CwxBinLogCursor* pCursor = binlogMgr->createCurser(ullSid);
      if (!pCursor) {
        iRet = CWX_MQ_ERR_ERROR;
        strcpy(pTss->m_szBuf2K, "Failure to create cursor");
        CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
        m_pApp->getTopicMgr()->freeBinlogMgrByTopic(*iter, binlogMgr);
        break;
      }
      CwxBinlogMgrCursor* item  = new CwxBinlogMgrCursor(*iter, binlogMgr, pCursor);
      m_syncSession->m_binlogCursor[*iter] = item;
      m_syncSession->m_unReadyBinlogCursor.push_back(item);
    }
    m_syncSession->m_ullStartSid = ullSid;

    ///发送session id的消息
    if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::packReportDataReply(pTss->m_pWriter,
        msg,
        m_header.getTaskId(),
        m_syncSession->m_ullSessionId,
        pTss->m_szBuf2K)) {
      CWX_ERROR(("Failure to pack sync data reply, err=%s, from:%s:%u", pTss->m_szBuf2K,
          m_strPeerHost.c_str(), m_unPeerPort));
      return -1;
    }
    msg->send_ctrl().setMsgAttr(CwxMsgSendCtrl::NONE);
    if (!putMsg(msg)) {
      CwxMsgBlockAlloc::free(msg);
      CWX_ERROR(("Failure push msg to send queue. from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      return -1;
    }
    ///发送发一条binlog
    int iState = syncSendBinLog(pTss);
    if (-1 == iState) {
      iRet = CWX_MQ_ERR_ERROR;
      CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    } else if (0 == iState) { ///产生continue的消息
      channel()->regRedoHander(this);
    }
    return 0;
  }while(0);
  ///到此一定错误
  CWX_ASSERT(CWX_MQ_ERR_SUCCESS != iRet);
  CwxMsgBlock* pBlock = NULL;
  if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::packSyncErr(pTss->m_pWriter,
      pBlock,
      m_header.getTaskId(),
      iRet,
      pTss->m_szBuf2K,
      pTss->m_szBuf2K)) {
    CWX_ERROR(("Failure to create binlog reply package, err:%s", pTss->m_szBuf2K));
    return -1;
  }
  pBlock->send_ctrl().setMsgAttr(CwxMsgSendCtrl::CLOSE_NOTICE);
  if (!putMsg(pBlock)) {
    CwxMsgBlockAlloc::free(pBlock);
    CWX_ERROR(("Failure push msg to send queue. from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
    return -1;
  }
  return 0;
}
Пример #16
0
void do_command(char *msg, Client *client)
{
	char *command,*p;
	int len;

	if(!msg || !strlen(msg) || !client)
		return;
	len=strlen(msg);
	p=msg;
	command=strsep(&p," \t");
	/* /NICK : change the clients name */
	if(!strcasecmp(command,"NICK"))
	{
		if(p && strlen(p))
		{
			char *old_name=client->name;

			fix_nick(p);
			if(!strlen(p))
			{
				putMsg(client->sock,"--- Invalid Nickname!");
				return;
			}
			if(!unique_nick(p))
			{
				putMsg(client->sock,"--- Duplicate Nickname!");
				return;
			}
			client->name=strdup(p);
			send_all(mformat("ssss","--- ",old_name," --> ",p));
			free(old_name);
		}
		else
			putMsg(client->sock,"--- /NICK nickname");
		return;
	}
	/* MSG : client to client message */
	if(!strcasecmp(command,"MSG"))
	{
		char *name;
		int to;

		if(p)
		{
			name=strsep(&p," ");
			to=find_client_name(name);
			if(to<0)
			{
				putMsg(client->sock, mformat("sss","--- /MSG nickname ",name," not found!"));
				return;
			}
			else if(p && strlen(p))
			{
				putMsg(client->sock,mformat("ssss",">",clients[to].name,"< ",p));
				putMsg(clients[to].sock,mformat("ssss",">",client->name,"< ",p));
				return;
			}
		}
		putMsg(client->sock,"--- /MSG nickname message...");
		return;
	}
	/* /ME : emote! to everyone */
	if(!strcasecmp(command,"ME"))
	{
		if(p && strlen(p))
		{
			send_all(mformat("sss",client->name," ",p));
		}
		else
			putMsg(client->sock,"--- /ME message...");
		return;
	}
	/* /QUIT : quit the server with a message */
	if(!strcasecmp(command,"QUIT"))
	{
		if(!p || strcasecmp(p,"-h"))
		{
			if(p)
				send_all(mformat("ssss","--- ",client->name," quits : ",p));
			else
				send_all(mformat("sss","--- ",client->name," quits"));
			remove_client(find_client(client->sock));
		}
		else
			putMsg(client->sock,"--- /QUIT [message...]");
		return;
	}
	/* /WHO : list the users online back to the client */
	if(!strcasecmp(command,"WHO"))
	{
		int i;
		IPaddress *ipaddr;
		Uint32 ip;
		const char *host=NULL;

		putMsg(client->sock,"--- Begin /WHO ");
		for(i=0;i<num_clients;i++)
		{
			ipaddr=SDLNet_TCP_GetPeerAddress(clients[i].sock);
			if(ipaddr)
			{
				ip=SDL_SwapBE32(ipaddr->host);
				host=SDLNet_ResolveIP(ipaddr);
				putMsg(client->sock,mformat("sssssdsdsdsdsd","--- ",clients[i].name,
						" ",host?host:"",
						"[",ip>>24,".", (ip>>16)&0xff,".", (ip>>8)&0xff,".", ip&0xff,
						"] port ",(Uint32)ipaddr->port));
			}
		}
		putMsg(client->sock,"--- End /WHO");
		return;
	}
Пример #17
0
int CwxMqInnerDispHandler::recvNewConnection(CwxMqTss* pTss) {
  int iRet = 0;
  CWX_UINT64 ullSession = 0;
  CwxMsgBlock* msg = NULL;
  do {
    if (!m_recvMsgData) {
      strcpy(pTss->m_szBuf2K, "No data.");
      CWX_ERROR(("Session connect-report package is empty, from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      iRet = CWX_MQ_ERR_ERROR;
      break;
    }
    ///禁止重复report sid。若cursor存在,表示已经报告过一次
    if (m_syncSession) {
      iRet = CWX_MQ_ERR_ERROR;
      CwxCommon::snprintf(pTss->m_szBuf2K, 2048,
          "Can't report sync sid duplicatly.");
      CWX_ERROR(("Session connect-report is duplicate, from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    ///获取报告的session id
    iRet = CwxMqPoco::parseReportNewConn(pTss->m_pReader,
        m_recvMsgData,
        ullSession,
        pTss->m_szBuf2K);
    if (CWX_MQ_ERR_SUCCESS != iRet) {
      CWX_ERROR(("Failure to parse report new conn msg, err=%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    if (m_sessions.find(ullSession) == m_sessions.end()) {
      iRet = CWX_MQ_ERR_ERROR;
      char szTmp[64];
      CwxCommon::snprintf(pTss->m_szBuf2K, 2048, "Session[%s] doesn't exist.",
          CwxCommon::toString(ullSession, szTmp, 10));
      CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    m_syncSession = m_sessions.find(ullSession)->second;
    m_ullSessionId = m_syncSession->m_ullSessionId;
    m_syncSession->addConn(this);
    ///发送下一条binlog
    int iState = syncSendBinLog(pTss);
    if (-1 == iState) {
      iRet = CWX_MQ_ERR_ERROR;
      CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    } else if (0 == iState) { ///产生continue消息
      channel()->regRedoHander(this);
    }
    return 0;
  } while(0);
  ///到此一定错误
  CWX_ASSERT(CWX_MQ_ERR_SUCCESS != iRet);
  if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::packSyncErr(pTss->m_pWriter,
      msg,
      m_header.getTaskId(),
      iRet,
      pTss->m_szBuf2K,
      pTss->m_szBuf2K)) {
    CWX_ERROR(("Failure to pack sync data reply, err=%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
    return -1;
  }
  msg->send_ctrl().setMsgAttr(CwxMsgSendCtrl::CLOSE_NOTICE);
  if (!putMsg(msg)) {
    CwxMsgBlockAlloc::free(msg);
    CWX_ERROR(("Failure push msg to send queue. from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
    return -1;
  }
  return 0;
}
Пример #18
0
 void ActionPutInto::printMessageDo(Systems::Manager& systems, json& arguments) const
 {
   auto& narrator = systems.narrator();
   arguments["preposition"] = tr("PREPOSITION_INTO");
   putMsg(narrator.makeTr("YOU_VERB_THE_FOO_PREPOSITION_TARGET", arguments));
 }
Пример #19
0
///0:未发送一条binlog;
///1:发送了一条binlog;
///-1:失败;
int CwxMqInnerDispHandler::syncSendBinLog(CwxMqTss* pTss) {
  int iRet = 0;
  CwxMsgBlock* pBlock = NULL;
  CWX_UINT32 uiKeyLen = 0;
  CWX_UINT32 uiTotalLen = 0;
  CWX_UINT64 ullSeq = m_syncSession->m_ullSeq;
  if (m_syncSession->m_topicIsChanged) {
    syncTopicState(pTss);
  }

  if (m_syncSession->m_uiChunk) pTss->m_pWriter->beginPack();
  while (1) {
    if (m_syncSession->m_unReadyBinlogCursor.size()) {
      if (syncSeekToReportSid(pTss) != 0) return -1;
    }
    if (1 != (iRet = syncSeekToBinlog(pTss))) break;
    //设置移到下一个记录位置
    m_syncSession->m_bNext = true;
    if (!m_syncSession->m_uiChunk) {
      iRet = syncPackOneBinLog(pTss->m_pWriter,
        pBlock,
        ullSeq,
        pTss->m_pBinlogData,
        pTss->m_szBuf2K);
      m_ullLastSid = m_syncSession->m_pBinlogCursor->m_pCursor->getHeader().getSid();
      break;
    } else {
      iRet = syncPackMultiBinLog(pTss->m_pWriter,
        pTss->m_pItemWriter,
        pTss->m_pBinlogData,
        uiKeyLen,
        pTss->m_szBuf2K);
      m_ullLastSid = m_syncSession->m_pBinlogCursor->m_pCursor->getHeader().getSid();
      if (1 == iRet) {
        uiTotalLen += uiKeyLen;
        if (uiTotalLen >= m_syncSession->m_uiChunk) break;
      }
      if (-1 == iRet) break;
      continue;
    }
  }

  if (-1 == iRet) return -1;
  if (!m_syncSession->m_uiChunk) { ///若不是chunk
    if (0 == iRet) return 0; ///没有数据
  } else {
    if (0 == uiTotalLen) return 0;
    pTss->m_pWriter->pack();
    if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::packMultiSyncData(0, pTss->m_pWriter->getMsg(),
      pTss->m_pWriter->getMsgSize(),
      pBlock,
      ullSeq,
      m_syncSession->m_bZip,
      pTss->m_szBuf2K))
    {
      return -1;
    }
  }
  ///根据svr类型,发送数据包
  pBlock->send_ctrl().setConnId(CWX_APP_INVALID_CONN_ID);
  pBlock->send_ctrl().setSvrId(CwxMqApp::SVR_TYPE_INNER_DISP);
  pBlock->send_ctrl().setHostId(0);
  pBlock->send_ctrl().setMsgAttr(CwxMsgSendCtrl::NONE);
  if (!putMsg(pBlock)) {
    CwxCommon::snprintf(pTss->m_szBuf2K, 2047, "Failure to send binlog");
    CWX_ERROR((pTss->m_szBuf2K));
    CwxMsgBlockAlloc::free(pBlock);
    return -1;
  }
  m_ullSendSeq = ullSeq;
  m_syncSession->m_ullSeq++;
  return 1; ///发送了一条消息
}
Пример #20
0
int CwxMqInnerDispHandler::recvReply(CwxMqTss* pTss) {
  int iRet = CWX_MQ_ERR_SUCCESS;
  CWX_UINT64 ullSeq = 0;
  CwxMsgBlock* msg = NULL;
  do {
    if (!m_syncSession) { ///如果连接不是同步状态,则是错误
      strcpy(pTss->m_szBuf2K, "Client no in sync state");
      CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      iRet = CWX_MQ_ERR_ERROR;
      break;
    }
    if (!m_recvMsgData) {
      strcpy(pTss->m_szBuf2K, "No data.");
      CWX_ERROR(("Sync reply package is empty, from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      iRet = CWX_MQ_ERR_ERROR;
      break;
    }
    ///若是同步sid的报告消息,则获取报告的sid
    iRet = CwxMqPoco::parseSyncDataReply(pTss->m_pReader, m_recvMsgData, ullSeq,
      pTss->m_szBuf2K);
    if (CWX_MQ_ERR_SUCCESS != iRet) {
      CWX_ERROR(("Failure to parse sync_data reply package, err:%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    if (ullSeq != m_ullSendSeq) {
      char szTmp1[64];
      char szTmp2[64];
      iRet = CWX_MQ_ERR_ERROR;
      CwxCommon::snprintf(pTss->m_szBuf2K, 2047,
        "Seq[%s] is not same with the connection's[%s].",
        CwxCommon::toString(ullSeq, szTmp1, 10),
        CwxCommon::toString(m_ullSendSeq, szTmp2, 10));
      CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      break;
    }
    ///发送下一条binlog
    int iState = syncSendBinLog(pTss);
    if (-1 == iState) {
      CWX_ERROR(("%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      return -1; ///关闭连接
    } else if (0 == iState) { ///产生continue的消息
      channel()->regRedoHander(this);
    }
    return 0;
  } while (0);
  ///到此一定错误
  CWX_ASSERT(CWX_MQ_ERR_SUCCESS != iRet);
  if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::packSyncErr(pTss->m_pWriter,
    msg,
    m_header.getTaskId(),
    iRet,
    pTss->m_szBuf2K,
    pTss->m_szBuf2K))
  {
    CWX_ERROR(("Failure to pack sync data reply, err=%s, from:%s:%u", pTss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
    return -1;
  }
  msg->send_ctrl().setMsgAttr(CwxMsgSendCtrl::CLOSE_NOTICE);
  if (!putMsg(msg)) {
    CwxMsgBlockAlloc::free(msg);
    CWX_ERROR(("Failure push msg to send queue. from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
    return -1;
  }
  return 0;
}