示例#1
0
        public void Init(EC.IApplication application)
        {
            Application = application;

            application.Disconnected += (o, e) =>
            {
                Interfaces.IUserAgent agent = (Interfaces.IUserAgent)e.Session[SESSION_KEY.USER];
                if (agent != null)
                {
                    if (agent.Room != null)
                    {
                        agent.Room.Exit(agent);
                    }
                    agent.Session = null;
                }
                e.Session[SESSION_KEY.USER] = null;
            };
            application.Connected += (o, e) =>
            {
            };
            application.Error += (o, e) =>
            {
                "{0} error {1}".Log4Error(e.Info.Error, "", "");
            };
        }
示例#2
0
 public void AddMessage(Protocol.IMessage message, Interfaces.IUserAgent user)
 {
     lock (this)
     {
         mQueue.Enqueue(new MessageToken {
             Message = message, UserAgent = user
         });
     }
 }
示例#3
0
        public string In(Interfaces.IUserAgent user, int seatIndex)
        {
            Protocol.Result result = new Protocol.Result();
            result.Success = true;

            if (user.Desk != null)
            {
                user.Desk.Exit(user);
            }
            for (int i = 0; i < Seats.Count; i++)
            {
                Interfaces.ISeat seat = Seats[i];
                if (seat.Index == seatIndex)
                {
                    lock (seat)
                    {
                        if (seat.User == null || seat.User == user)
                        {
                            if (user.Seat != null)
                            {
                                user.Seat.User = null;
                            }
                            seat.User = user;
                            user.Desk = this;
                            user.Seat = seat;
                            Room.UpdateDesk(this);
                        }
                        else
                        {
                            result.Success = false;
                            return("位置已经被占用!");
                        }
                    }
                }
            }
            lock (Visitors)
            {
                if (!Visitors.Contains(user))
                {
                    Visitors.Add(user);
                }
                System.Threading.Interlocked.Increment(ref mVersion);
            }
            return(null);
        }
示例#4
0
 public void Exit(Interfaces.IUserAgent user)
 {
     if (user.Desk == this)
     {
         if (user.Seat != null)
         {
             user.Seat.User = null;
         }
         user.Seat = null;
         user.Desk = null;
         lock (Visitors)
         {
             Visitors.Remove(user);
             System.Threading.Interlocked.Increment(ref mVersion);
         }
         Room.UpdateDesk(this);
     }
 }
示例#5
0
 protected abstract void OnExecute(T message, EC.ISession session, Interfaces.IUserAgent agent, Interfaces.ISiqiServer server);
示例#6
0
 public UserSegment(int count)
 {
     mUsers = new Interfaces.IUserAgent[count];
 }
示例#7
0
 protected override void OnExecute(Protocol.Login message, EC.ISession session, Interfaces.IUserAgent agent, Interfaces.ISiqiServer server)
 {
     Protocol.LoginResponse response = new Protocol.LoginResponse();
     response.MsgID   = message.MsgID;
     response.Success = false;
     try
     {
         Interfaces.Data.Model.User user = server.LoginHandler.Login(message.EMail, message.Password);
         if (user != null)
         {
             agent = server.GetUser(message.EMail);
             if (agent == null)
             {
                 agent = new UserAgent(user, session);
                 server.AddUser(agent);
             }
             else
             {
                 agent.Session = session;
             }
             session[SESSION_KEY.USER] = agent;
             response.Tokey            = message.EMail;
             response.Success          = true;
             session.Channel.Status    = Beetle.Express.ChannelStatus.security;
         }
         else
         {
             response.Message = "用户名和密码不正确!";
         }
     }
     catch (Exception e_)
     {
         response.Message = e_.Message;
     }
     server.Send(response, session);
 }
示例#8
0
        protected override void OnExecute(Protocol.SelectRoom message, EC.ISession session, Interfaces.IUserAgent agent, Interfaces.ISiqiServer server)
        {
            Protocol.SelectRoomResponse response = new Protocol.SelectRoomResponse();
            response.MsgID   = message.MsgID;
            response.Success = false;
            IRoom room = server.GetRoom(message.Room);

            if (room != null)
            {
                room.In(agent);
                response.Success = true;
                response.Room    = room.ID;
            }
            else
            {
                response.Message = "room not found!";
            }
            server.Send(response, session);
        }
示例#9
0
 protected override void OnExecute(Protocol.ListRoom message, EC.ISession session, Interfaces.IUserAgent agent, Interfaces.ISiqiServer server)
 {
     Protocol.ListRoomResponse response = server.ListRoom();
     response.MsgID = message.MsgID;
     server.Send(response, session);
 }
示例#10
0
 protected override void OnExecute(Protocol.GetRoom message, EC.ISession session, Interfaces.IUserAgent agent, Interfaces.ISiqiServer server)
 {
     Protocol.RoomInfoDetail result = new Protocol.RoomInfoDetail();
     result.Success = true;
     try
     {
         Interfaces.IRoom room = server.GetRoom(message.Room);
         if (room != null)
         {
             result         = room.GetInfoDetail();
             result.Success = true;
         }
         else
         {
             result.Success = false;
             result.Message = "房间不存在!";
         }
     }
     catch (Exception e_)
     {
         result.Success = false;
         result.Message = e_.Message;
     }
     server.Send(result, agent);
 }
示例#11
0
 protected override void OnExecute(Protocol.SelectDesk message, EC.ISession session, Interfaces.IUserAgent agent, Interfaces.ISiqiServer server)
 {
     Interfaces.IRoom room = server.GetRoom(message.Room);
     if (room != null)
     {
         room.AddMessage(message, agent);
     }
     else
     {
         Protocol.SelectDeskResponse response = new Protocol.SelectDeskResponse();
         response.Success = false;
         response.Message = "所在房间不存在!";
         server.Send(response, session);
     }
 }