コード例 #1
0
 public Room(SocketModel sm)
 {
     LastPlayer = null;
     Add(sm);
     InitCards();
     Mix();
 }
コード例 #2
0
        public void AccceptOpponent()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketlist2[currentClient] = new SocketModel(s);
        }
コード例 #3
0
 public void TransData(SocketModel s, string str)
 {
     if (CurrentPlayer.SocketPlayer == s)
     {
         data = str;
     }
 }
コード例 #4
0
 public void TransData(SocketModel s, string str)
 {
     if (CurrentPlayer == s.GetRemoteEndpoint())
     {
         data = str;
     }
 }
コード例 #5
0
ファイル: Session.cs プロジェクト: M9L6/ARFunServer
        public void write(int type, int command, string name, string message)
        {
            SocketModel model     = new SocketModel(type, command, name, message);
            ByteArray   byteArray = new ByteArray();

            byteArray.WriteInt(model.type);
            byteArray.WriteInt(model.command);
            if (!string.IsNullOrEmpty(model.name))
            {
                byte[] bs1 = Encoding.UTF8.GetBytes(model.name);
                byteArray.WriteInt(bs1.Length);
                byteArray.WriteBytes(bs1);
            }
            else
            {
                byteArray.WriteInt(0);
            }
            if (!string.IsNullOrEmpty(model.message))
            {
                byte[] bs2 = Encoding.UTF8.GetBytes(model.message);
                byteArray.WriteInt(bs2.Length);
                byteArray.WriteBytes(bs2);
            }
            else
            {
                byteArray.WriteInt(0);
            }

            socket.Send(byteArray.Buffer);
        }
コード例 #6
0
 public void Cancel(SocketModel s)
 {
     for (int i = 0; i < players.Count; i++)
     {
         if (players[i].SocketPlayer == s)
         {
             players[i].PlayerStatus = false;
         }
     }
 }
コード例 #7
0
 //void StartGame1()
 //{
 //    serverbot = new Bot[4 - players.Count];
 //    Playing = true;
 //    int count = 0;
 //    int i = FindFistTurn();
 //    PreviousCard = "|";
 //    Mix();
 //    SendCard();
 //    for(int y=0;y<serverbot.Length;y++)
 //    {
 //        List<Card> temp = new List<Card>();
 //        for (int x = 51 - y * 13; x > 51 - y * 13 - 13; x--)
 //            temp.Add(Cards[x]);
 //     serverbot[y] = new Bot(temp,y.);
 //    }
 //    while(players.Count>0)
 //    {
 //        if(i>=players.Count)
 //        {
 //            if()
 //            serverbot[i-players.Count].
 //        }
 //    }
 //}
 public void SendOtherPlayer(SocketModel s, string str)
 {
     for (int i = 0; i < players.Count; i++)
     {
         if (s != players[i].SocketPlayer)
         {
             players[i].SocketPlayer.SendData("PlayerTurn" + str);
         }
     }
 }
コード例 #8
0
 //BeginInvoke((Action)(() => CountDownTimer.Start()));
 public void OutRoom(SocketModel s)
 {
     for (int i = 0; i < players.Count; i++)
     {
         if (players[i].SocketPlayer == s)
         {
             players.Remove(players[i]);
         }
     }
 }
コード例 #9
0
ファイル: Server.cs プロジェクト: gametienlen/280599
        public void Accept2()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketList2[currentClient] = new SocketModel(s);
            string str = socketList2[currentClient].GetRemoteEndpoint();

            txbConnectionManager.AppendText("\nNew connection from: " + str + "id" + currentClient + "\n");
        }
コード例 #10
0
        public void Accept()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketList[currentClient] = new SocketModel(s);
            string str  = socketList[currentClient].GetRemoteEndpoint();
            string str1 = "New connection from: " + str + "\n";

            textBox3.AppendText(str1);
        }
コード例 #11
0
        public override void MessageReceive(UserToken token, object message)
        {
            Console.WriteLine("有客户发送消息了");
            SocketModel model = message as SocketModel;

            switch (model.type)
            {
            case Protocol.TYPE_LOGIN:
                login.MessageReceive(token, model);
                break;
            }
        }
コード例 #12
0
        public void Accept()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketlist1[currentClient] = new SocketModel(s);

            string st  = socketlist1[currentClient].GetRemoteEndpoint();
            string st1 = "New connect from: " + st;

            Console.WriteLine(st1);
            lbManageConnect.Items.Add(st1);
        }
コード例 #13
0
 public void process(Session session, SocketModel model)
 {
     try
     {
         if (!AccountManager.Accounts.Contains(session))
         {
             AccountManager.Accounts.Add(session);
         }
     }
     catch (Exception e)
     {
         Log.form.AddText(e.ToString());
     }
 }
コード例 #14
0
ファイル: Server.cs プロジェクト: mucanson/TienlenCsharp
        public SocketModel Accept()
        {
            int         status = -1;
            Socket      s      = tcp.SetUpANewConnection(ref status);
            SocketModel player = new SocketModel(s);
            //Room.Add(player);
            //socketList[currentClient] = new SocketModel(s);
            //string str = socketList[currentClient].GetRemoteEndpoint();
            string str  = player.GetRemoteEndpoint();
            string str1 = "New connection from: " + str + "\n";

            textBox3.AppendText(str1);
            return(player);
        }
コード例 #15
0
ファイル: Server.cs プロジェクト: mucanson/TienlenCsharp
 public int SearchEmtyRoom(SocketModel sm)
 {
     for (int i = 0; i < Room.Count; i++)
     {
         if (Room[i].NumOfPlayer() == 0)
         {
             Room[i].Add(sm);
             Console.WriteLine(i);
             return(i);
         }
     }
     Console.WriteLine(-1);
     return(-1);
 }
コード例 #16
0
ファイル: Server.cs プロジェクト: mucanson/TienlenCsharp
 public int RoomSearching(SocketModel sm)
 {
     for (int i = 0; i < Room.Count; i++)
     {
         if (Room[i].CanJoin())
         {
             Room[i].Add(sm);
             Console.WriteLine(i);
             return(i);
         }
     }
     Console.WriteLine(-1);
     return(-1);
 }
コード例 #17
0
 public void Add(SocketModel a)
 {
     clients.Add(a); count++;
     if (Check())
     {
         Shuffle();                         //
         currentPlayer = CheckFirst() / 13; //2;////init curr player that have 3.1
         Deal();                            //
         Thread l = new Thread(Play);       //play turn
         l.Start();
         if (done)
         {
             l.Abort(); count = 0; clients.Clear();
         }
     }
 }
コード例 #18
0
        public void Ready(SocketModel s)
        {
            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].SocketPlayer == s)
                {
                    players[i].PlayerStatus = true;
                }
            }

            if (ReadyToStar())
            {
                Thread t = new Thread(StartGame);
                t.IsBackground = true;
                t.Start();
            }
        }
コード例 #19
0
ファイル: LogicHandler.cs プロジェクト: M9L6/ARFunServer
        public void process(Session session, SocketModel model)
        {
            try
            {
                switch (model.type)
                {
                case Type.Create:
                    CreateHandler.GetInstance().process(session, model);
                    break;

                case Type.SendMessage:
                    SendMessageHandler.GetInstance().process(session, model);
                    break;

                default:

                    break;
                }
            }
            catch (Exception e)
            {
                Log.form.AddText(e.ToString());
            }
        }
コード例 #20
0
        public void process(Session session, SocketModel model)
        {
            try
            {
                switch (model.command)
                {
                case Command.GetComments:

                    if (!AccountManager.Comments.ContainsKey(model.name))
                    {
                        session.write(model.type, model.command, model.name, string.Empty);
                    }
                    else
                    {
                        for (int i = 0; i < AccountManager.Comments[model.name].Count; i++)
                        {
                            session.write(model.type, model.command, model.name, AccountManager.Comments[model.name][i]);
                        }
                    }

                    break;

                case Command.SendComment:



                    DataManager.GetInstance().SaveData(model.name, model.message);

                    if (!AccountManager.Comments.ContainsKey(model.name))
                    {
                        DataManager.GetInstance().SaveNameData(model.name);


                        List <string> comments = new List <string>();
                        comments.Add(model.message);
                        AccountManager.Comments.Add(model.name, comments);
                    }
                    else
                    {
                        AccountManager.Comments[model.name].Add(model.message);
                    }



                    foreach (Session s in AccountManager.Accounts)
                    {
                        if (s != session)
                        {
                            s.write(model.type, model.command, model.name, model.message);
                        }
                    }

                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Log.form.AddText(e.ToString());
            }
        }
コード例 #21
0
 public Player(SocketModel s)
 {
     SocketPlayer = s;
     PlayerStatus = false;
 }
コード例 #22
0
 public void Add(SocketModel s)
 {
     players.Add(new Player(s));
 }
コード例 #23
0
ファイル: Server.cs プロジェクト: mucanson/TienlenCsharp
        public void Commmunication(object obj)
        {
            int         RoomIndex = -1;
            SocketModel sm        = (SocketModel)obj;

            try
            {
                while (sm.IsAlive())
                {
                    string str = sm.ReceiveData();
                    if (str.Length == 0)
                    {
                        sm.CloseSocket();
                        return;
                    }
                    switch (str)
                    {
                    case "Search":
                        RoomIndex = RoomSearching(sm);
                        if (RoomIndex == -1)
                        {
                            RoomIndex = RoomCreate(sm);
                        }
                        if (RoomIndex != -1)
                        {
                            sm.SendData("#RoomFound|" + RoomIndex);
                        }
                        break;

                    case "Ready":
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].Ready(sm);
                        }
                        break;

                    case "Cancel":
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].Cancel(sm);
                        }
                        break;

                    case "Create":
                        RoomIndex = SearchEmtyRoom(sm);
                        if (RoomIndex == -1)
                        {
                            RoomIndex = RoomCreate(sm);
                        }
                        if (RoomIndex != -1)
                        {
                            sm.SendData("#CreateRoomSuccessful|" + RoomIndex);
                        }
                        break;

                    case "Exit":
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].Remote(sm);
                            RoomIndex = -1;
                            sm.SendData("#Exit");
                        }
                        break;

                    default:
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].TransData(sm, str);
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace.ToString());
                sm.CloseSocket();
            }
        }
コード例 #24
0
ファイル: Server.cs プロジェクト: mucanson/TienlenCsharp
 public int RoomCreate(SocketModel sm)
 {
     Room.Add(new Room1(sm));
     return(Room.Count - 1);
 }
コード例 #25
0
 public Room1(SocketModel sm)
 {
     Add(sm);
     InitCards();
     Mix();
 }