Changeset 0cc431d in network-game


Ignore:
Timestamp:
Nov 26, 2012, 5:55:19 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d2b411a
Parents:
2488852
Message:

Added a state to the client and began using message types. Created a simple system for sending the username to the server before being logged in

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r2488852 r0cc431d  
    4343const int BOUNCER_SIZE = 32;
    4444enum MYKEYS {
    45    KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
     45   KEY_UP,
     46   KEY_DOWN,
     47   KEY_LEFT,
     48   KEY_RIGHT
     49};
     50
     51enum STATE {
     52   STATE_START,
     53   STATE_LOGIN
    4654};
    4755 
     
    5866   bool doexit = false;
    5967
     68   int state = STATE_START;
     69
    6070   chat chatConsole;
    6171
     
    130140   struct sockaddr_in server, from;
    131141   struct hostent *hp;
    132    char buffer[256];
     142   //char buffer[256];
    133143   NETWORK_MSG msgTo, msgFrom;
    134144
     
    200210               cout << "input: " << input << endl;
    201211               strcpy(msgTo.buffer, input.c_str());
    202                
     212
     213               switch(state)
     214               {
     215               case STATE_START:
     216                  msgTo.type = MSG_TYPE_LOGIN;
     217                  break;
     218               case STATE_LOGIN:
     219                  msgTo.type = MSG_TYPE_CHAT;
     220                  break;
     221               default:
     222                  cout << "The state has an invalid value: " << state << endl;
     223                  break;
     224               }
     225
    203226               n=sendMessage(&msgTo, sock, &server);
    204227               if (n < 0)
     
    209232                  error("receiveMessage");
    210233
    211                chatConsole.addLine(string(msgFrom.buffer));
    212                cout << "Added new line" << endl;
     234               switch(state)
     235               {
     236               case STATE_START:
     237                  state = STATE_LOGIN;
     238                  break;
     239               case STATE_LOGIN:
     240                  chatConsole.addLine(string(msgFrom.buffer));
     241                  cout << "Added new line" << endl;
     242                  break;
     243               default:
     244                  cout << "The state has an invalid value: " << state << endl;
     245                  break;
     246               }
    213247            }
    214248         }else {
  • common/message.h

    r2488852 r0cc431d  
    22#define _MESSAGE_H
    33
    4 #define MSG_TYPE_SOMETHING 1000
     4#define MSG_TYPE_LOGIN  1
     5#define MSG_TYPE_CHAT   2
    56
    67typedef struct
Note: See TracChangeset for help on using the changeset viewer.