void CanvasHandler::send( Connector *conn, const char *data, int dataSize ) { assert(dataSize > 0); _sndBuf->resize(dataSize+MESSAGE_HEADER); _sndBuf->copy( MESSAGE_HEADER, data, dataSize ); MAKE_MSG(_sndBuf->buffer(),messages::canvasCommand,_sndBuf->length()); conn->send( _sndBuf ); }
void VideoResizeHandler::send( Connector *conn, AVDescriptor* descriptor ) { char buf[AV_DESCRIPTOR_BUF_SIZE]; char *ptr = (char *)MSG_PAYLOAD(buf); int offset = 0; float value = descriptor->getX(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset+=FLOAT_SIZE; value = descriptor->getY(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset+=FLOAT_SIZE; value = descriptor->getWidth(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset+=FLOAT_SIZE; value =descriptor->getHeight(); memcpy(ptr+offset, &value, FLOAT_SIZE ); offset += FLOAT_SIZE; MAKE_MSG(buf,messages::videoResize,offset+MESSAGE_HEADER); util::Buffer msg( buf, offset+MESSAGE_HEADER, false ); conn->send( &msg ); }
void cGameServer::doCreateAccount(int index,char *pass,char *conf,char *email) { //password must match confirmation if(strcmp(pass,conf)!=0) { sendChatMsg(itod(index),"^BPassword confirmation does not match original"); return; } //check length of password if(strlen(pass)<4 || strlen(pass)>16) { sendChatMsg(itod(index),"^BPassword must be between 4 and 16 characters in length."); return; } //no duplicate emails if(mydb.emailExists(email)) { sendChatMsg(itod(index),"^BThere is already an account using that email address."); return; } //generate unique 7 number id char id[256]; sprintf(id,"%d%d",(rand()%8000)+1999,(rand()%800)+199); while(mydb.accountExists(id)) sprintf(id,"%d%d",(rand()%8000)+1999,(rand()%800)+199); //send email and create account char body[1024]; sprintf(body,"Welcome to Mystera Legends!\n" "Make sure to write down your account\n" "information so you dont lose it:\n" "Account ID:%s\n" "Password :%s\n" ,id,pass); /*sendEmail( "mail.mysteralegends.com", "c3RlZWw5OQ==", "MDBqdWJibGU=", "*****@*****.**", email, "Mystera Legends account information", body);*/ mydb.createAccount(id,MD5.crypt(pass),email,player[index].ip); char themsg[128]; sprintf(themsg,"^BAccount created. Please write down your new account ID: ^G%s",id); sendChatMsg(itod(index),themsg); MAKE_MSG(dlog_msg,pmsg,DLOG_MSG); pmsg.dialog=1; nh.send((unsigned char *)&pmsg,sizeof(dlog_msg),SEND_GUARANTEED,itod(index)); }
void KeyEventHandler::send( Connector *conn, util::key::type key, bool isUp ) { util::BYTE buf[KEY_BUFFER]; int pos=MESSAGE_HEADER; { // Copy Key // Convert to DWORD (4 bytes) util::DWORD value = static_cast<util::DWORD>( key ); int index=0; util::BYTE *ptr = (util::BYTE *)&value; // Copy 4 bytes buf[pos++] = ptr[index++]; buf[pos++] = ptr[index++]; buf[pos++] = ptr[index++]; buf[pos++] = ptr[index++]; } // Copy state buf[pos++] = isUp ? 1 : 0; MAKE_MSG(buf,messages::keyEvent,pos); util::Buffer msg( (char *)buf, pos, false ); conn->send( &msg ); }
void doFrame() { if(Input::IsKeyDown(SDLK_LCTRL) && Input::IsPressed(SDLK_q)) { if(connected) { MAKE_MSG(quit_msg,msg,QUIT_MSG); nc.send((unsigned char *)&msg,sizeof(quit_msg),SEND_GUARANTEED); } else done=1; } if ((Input::IsKeyDown(SDLK_LALT) || Input::IsKeyDown(SDLK_RALT)) && Input::IsPressed(SDLK_RETURN)) { fullscreen = !fullscreen; Renderer::SetFullscreen(fullscreen); // The next block of code is stupid nonsense crap because it is already setup. // There is no reason to reload EVERYTHING just because we are going to fullscreen. /*initializeSystem(); Renderer::Clear(); Renderer::LoadIdentity(); //load images and sounds char pnum[32]; int i; soundMax=-1; bodyMax=-1; hairMax=-1; clothesMax=-1; monsterMax=-1; for(i=0;i<255;i++) { if(soundMax==-1) { sprintf(pnum,"data/sounds/%d.wav",i); if(!sounds.Load(i,pnum)) soundMax=i; } if(bodyMax==-1) { sprintf(pnum,"data/body/%d.png",i); if(!pBody[i].Load(pnum)) bodyMax=i; } if(hairMax==-1) { sprintf(pnum,"data/hair/%d.png",i); if(!pHair[i].Load(pnum)) hairMax=i; } if(clothesMax==-1) { sprintf(pnum,"data/clothes/%d.png",i); if(!pClothes[i].Load(pnum)) clothesMax=i; } if(monsterMax==-1 && i>0) { sprintf(pnum,"data/monsters/%d.png",i); if(!pMonster[i].Load(pnum)) monsterMax=i; } } tiledata.Load("data/misc/tiledata.png"); effdata.Load("data/misc/effects.png"); itemdata.Load("data/misc/items.png"); loading.Load("data/misc/loading.png"); skin.Load("data/misc/skin0.png"); //load fonts font.Load("data/misc/font.png"); TEXTDRAWER.Initialize(font.img); TEXTDRAWER.setColor(0,0,0,1); //create effects,terminal,dialog boxes eff.create(MAX_EFFECTS); bar.create(MAX_HPBAR); term.create(255,11); // setupDialogs(); loadEffectsMap(); updateFPS();*/ //render images doGameGraphics(); } if(Input::IsPressed(SDLK_F5))//change skins { guiskin++; char name[256]; sprintf(name,"data/misc/skin%d.png",guiskin); FILE *f=fopen(name,"r"); if(f==NULL) { guiskin=0; sprintf(name,"data/misc/skin%d.png",guiskin); skin.Load(name); } else { fclose(f); f=0; skin.Load(name); } } if(Input::IsPressed(SDLK_ESCAPE)) { target=-1; mtarget_id=-1; MAKE_MSG(trgt_msg,tr,TRGT_MSG); tr.index=mtarget_id; nc.send((unsigned char *)&tr,sizeof(trgt_msg),SEND_GUARANTEED); ptarget_id=-1; chatting=0; Input::ResetString(); } if(connected && dialog==-1 && Input::IsPressed(SDLK_RETURN) && !Input::IsKeyDown(SDLK_LALT) && !Input::IsKeyDown(SDLK_RALT)) { if(chatting) { if(strlen(Input::GetString())==0) chatting=0; } else chatting=1; } if(connected && me > -1 && MYGUY.access > 5) { if(Input::IsPressed(SDLK_F1)) { target=-1; if(mode==1) mode=0; else mode=1; } if(Input::IsPressed(SDLK_F11)) //debug { if(debug==1) debug=0; else debug=1; } } if(me > -1 && !chatting && dialog==-1 && MYGUY.hp>0 && (strcmp(world[MYGUY.p.map].name,"_EMPTY_")!=0 || mode==1)) doGameInput(); else if((ptarget_id!=-1&&MYGUY.front()==player[ptarget_id].p)&& attackTimer.tick(50)) attack(); if(dialog==-1 && chatting && Input::StringInput(240)) { if(parse(Input::GetString())) { if(me > -1) { //sprintf(temp,"%s:%s",MYGUY.name, Input::GetString()); //term.newLine("Here is a very long sentence i am using to test with will you please split it up correctly at the spaces so it will wrap around, thank you very much sir..."); //term.newLine(Input::GetString()); //balloon.add(Input::GetString(),me); MAKE_MSG(chat_msg,reply,CHAT_MSG); reply.size=strlen(Input::GetString())+1;//+1 for null char buf[256]; char *InputString = Input::GetString(); memcpy(&buf,(void *)&reply,sizeof(chat_msg));//store header memcpy(buf+sizeof(chat_msg),(void *)&InputString,reply.size);//store string nc.send((unsigned char *)&buf,sizeof(chat_msg)+reply.size,SEND_GUARANTEED); chatting=0; } } else if(me > -1) { chatting=0; } Input::ResetString(); } updateFPS(); //render images Renderer::Clear(); Renderer::LoadIdentity(); doGameGraphics(); /*TEXTDRAWER.setColor(1,1,1,1);//draw bottleneck stats for(int i=0;i<4;i++) TEXTDRAWER.PrintText(10,50+i*20,"%d) %d",i,bottle.times[i]); TEXTDRAWER.defaultColor();*/ if(mode==1) { doMapDialog(); int r=mapDialog.modified(); if(r>-1) mapEvent(r); } //if(keyDown[SDLK_HOME]) // term.renderAll(0,200); //else term.render(0,480,246-chat_scroll,9); if(dialog!=-1) { vDialog[dialog].draw(); if(dialog==4)//draw sprites { if(animTimer.tick(400)) animSel=abs(animSel-1); TEXTDRAWER.PrintTextf(vDialog[4].x+160,vDialog[4].y+162,"%d",bodySel); TEXTDRAWER.PrintTextf(vDialog[4].x+160,vDialog[4].y+162+35,"%d",clothesSel); TEXTDRAWER.PrintTextf(vDialog[4].x+160,vDialog[4].y+162+70,"%d",hairSel); drawChar(vDialog[4].x+10,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,0,animSel,4); drawChar(vDialog[4].x+90,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,1,animSel,4); drawChar(vDialog[4].x+170,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,2,animSel,4); drawChar(vDialog[4].x+250,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,3,animSel,4); } else if(dialog==6) { if(animTimer.tick(400)) animSel=abs(animSel-1); for(int i=0; i<4; i++)if(slot[i].lvl>0) { TEXTDRAWER.PrintTextf(vDialog[6].x+16+128*i,vDialog[6].y+162,"%s",slot[i].name); TEXTDRAWER.PrintTextf(vDialog[6].x+16+128*i,vDialog[6].y+162+16,"Level %d",slot[i].lvl); drawChar(vDialog[6].x+10+128*i,vDialog[6].y+10,slot[i].sprite,slot[i].body,slot[i].clothes,slot[i].hair,0,animSel,4); TEXTDRAWER.PrintTextf(vDialog[6].x+28+128*i,vDialog[6].y+196,"Use"); } else TEXTDRAWER.PrintTextf(vDialog[6].x+28+128*i,vDialog[6].y+196,"New"); } int r=vDialog[dialog].modified(); if(r!=-1) dialogEvent(r); } else { if(me>-1 && strcmp(world[MYGUY.p.map].name,"_EMPTY_")==0) { loading.blitFast(150,150,float(Input::MouseX())/640.0f,float(Input::MouseY())/480.0f); } if(chatting) { char temp[256]; int x=0,len; sprintf(temp,"Send:%s_",Input::GetString()); len=pWidth(temp); if(len>636) x=636-len; TEXTDRAWER.setColor(1,1,1,1); TEXTDRAWER.PrintText(x,585,temp); TEXTDRAWER.defaultColor(); } } //cursor skin.blit(Input::MouseX(),Input::MouseY(),64,0,32,32,1,1); Renderer::Swap(); }