Ejemplo n.º 1
0
        void c2s_stub_OnReqLogout(NetIncomingMessage im, C2S.Message.ReqLogout data)
        {
            ConnectedUser user = client_list[im.SenderConnection];

            if (user == null)
            {
                user = idx_id_for_client_list[data.id];
            }
            if (user == null)
            {
                im.SenderConnection.Disconnect("You are not logged in.");
                return;
            }

            client_list.Remove(im.SenderConnection);
            idx_id_for_client_list.Remove(data.id);

            if (user.connection != null)
            {
                s2c_proxy.NotifyLogout(user.connection, user.id);
            }

            foreach (var client in client_list.Values)
            {
                s2c_proxy.NotifyLogout(client.connection, user.id);
            }

            Console.WriteLine("{0} logout from {1}.", user.id, im.SenderEndPoint.ToString());
        }
Ejemplo n.º 2
0
        void c2s_stub_OnHeartbeat(NetIncomingMessage im, C2S.Message.Heartbeat data)
        {
            //Console.WriteLine("OnHeartbeat...[ThreadID:{0}]", Thread.CurrentThread.ManagedThreadId);

            ConnectedUser user = client_list[im.SenderConnection];

            if (user == null)
            {
                im.SenderConnection.Disconnect("You are not logged in.");
                return;
            }
            user.last_heartbeat_ticks = DateTime.Now.Ticks;
        }
Ejemplo n.º 3
0
        void c2s_stub_OnReqSendAll(NetIncomingMessage im, C2S.Message.ReqSendAll data)
        {
            Console.WriteLine("OnReqSendAll...[ThreadID:{0}]", Thread.CurrentThread.ManagedThreadId);

            ConnectedUser user = client_list[im.SenderConnection];

            if (user == null)
            {
                im.SenderConnection.Disconnect("You are not logged in.");
                return;
            }

            foreach (var client in client_list.Values)
            {
                s2c_proxy.NotifySendAll(client.connection, user.id, data.message);
            }

            s2c_proxy.ResSendAll(user.connection, (short)S2C.Message.Flag.kFlagSuccess, "Success");

            Console.WriteLine("{0} sent a message[{1}] to all from {2}.", user.id, data.message, im.SenderEndPoint.ToString());
        }
Ejemplo n.º 4
0
        void c2s_stub_OnReqSend(NetIncomingMessage im, C2S.Message.ReqSend data)
        {
            ConnectedUser user = client_list[im.SenderConnection];

            if (user == null)
            {
                im.SenderConnection.Disconnect("You are not logged in.");
                return;
            }

            ConnectedUser to_user = idx_id_for_client_list[data.to_id];

            if (to_user == null)
            {
                s2c_proxy.ResSend(user.connection, (short)S2C.Message.Flag.kFlagFail, "Can't find user.", data.to_id);
                return;
            }

            s2c_proxy.NotifySend(to_user.connection, user.id, data.message);
            s2c_proxy.ResSend(user.connection, (short)S2C.Message.Flag.kFlagSuccess, "Success", data.to_id);

            //Console.WriteLine("{0} sent a message[{1}] to {2} from {3}.", user.id, data.message, data.to_id, im.SenderEndPoint.ToString());
        }
Ejemplo n.º 5
0
        void c2s_stub_OnReqLogin(NetIncomingMessage im, C2S.Message.ReqLogin data)
        {
            if (client_list.ContainsKey(im.SenderConnection))
            {
                Console.WriteLine("{0} has already logged in.", data.id);
                return;
                //client_list[im.SenderConnection].Disconnect("Try to login from another site. You will be disconnected from server.");
            }
            if (idx_id_for_client_list.ContainsKey(data.id))
            {
                Console.WriteLine("{0} has already logged in from {1}.", data.id, idx_id_for_client_list[data.id].connection.RemoteEndPoint.ToString());
                return;
                //client_list[im.SenderConnection].Disconnect("Try to login from another site. You will be disconnected from server.");
            }
            ConnectedUser user = new ConnectedUser();

            user.connection           = im.SenderConnection;
            user.id                   = data.id;
            user.last_heartbeat_ticks = DateTime.Now.Ticks;

            client_list[im.SenderConnection] = user;
            idx_id_for_client_list[data.id]  = user;

            s2c_proxy.ResLogin(im.SenderConnection, (short)S2C.Message.Flag.kFlagSuccess);

            foreach (var client in client_list.Values)
            {
                if (client.connection == im.SenderConnection)
                {
                    continue;
                }
                s2c_proxy.NotifyLogin(client.connection, data.id);
            }

            Console.WriteLine("{0} login from {1}", data.id, im.SenderEndPoint.ToString());
        }
Ejemplo n.º 6
0
        void c2s_stub_OnReqLogin(NetIncomingMessage im, C2S.Message.ReqLogin data)
        {
            if (client_list.ContainsKey(im.SenderConnection))
            {
                Console.WriteLine("{0} has already logged in.", data.id);
                return;
                //client_list[im.SenderConnection].Disconnect("Try to login from another site. You will be disconnected from server.");
            }
            if (idx_id_for_client_list.ContainsKey(data.id))
            {
                Console.WriteLine("{0} has already logged in from {1}.", data.id, idx_id_for_client_list[data.id].connection.RemoteEndPoint.ToString());
                return;
                //client_list[im.SenderConnection].Disconnect("Try to login from another site. You will be disconnected from server.");
            }
            ConnectedUser user = new ConnectedUser();
            user.connection = im.SenderConnection;
            user.id = data.id;
            user.last_heartbeat_ticks = DateTime.Now.Ticks;

            client_list[im.SenderConnection] = user;
            idx_id_for_client_list[data.id] = user;

            s2c_proxy.ResLogin(im.SenderConnection, (short)S2C.Message.Flag.kFlagSuccess);

            foreach (var client in client_list.Values)
            {
                if (client.connection == im.SenderConnection) continue;
                s2c_proxy.NotifyLogin(client.connection, data.id);
            }

            Console.WriteLine("{0} login from {1}", data.id, im.SenderEndPoint.ToString());
        }