Ejemplo n.º 1
0
 public static bool Interpret(int clientId, IMessage message, IServerService service)
 {
     switch (message.Header)
       {
     case MessageHeaders.LOGIN:
       MessageHelper.ResolveMessage(message, reader => service.Login(clientId, reader.ReadString()));
       break;
     case MessageHeaders.COMPLETELOGIN:
       MessageHelper.ResolveMessage(message, reader => service.CompleteLogin(clientId, reader.ReadAvatar()));
       break;
     case MessageHeaders.SEND_MESSAGE:
       MessageHelper.ResolveMessage(message, reader =>
     service.SendMessage(clientId, reader.ReadArray((Func<int>)reader.ReadUserId), reader.ReadString()));
       break;
     case MessageHeaders.BROADCAST:
       MessageHelper.ResolveMessage(message, reader =>
     service.BroadcastMessage(clientId, reader.ReadString()));
       break;
     case MessageHeaders.LOGOUT:
       service.Logout(clientId);
       break;
     case MessageHeaders.CHANGE_STATE:
       MessageHelper.ResolveMessage(message, reader => service.ChangeState(clientId, reader.ReadUserState()));
       break;
     case MessageHeaders.CHANGE_INFO:
       MessageHelper.ResolveMessage(message, reader =>
     service.ChangeInfo(clientId, reader.ReadUserState(), reader.ReadString()));
       break;
     default:
       return false;
       }
       return true;
 }