public Room(SocketModel sm) { LastPlayer = null; Add(sm); InitCards(); Mix(); }
public void AccceptOpponent() { int status = -1; Socket s = tcp.SetUpANewConnection(ref status); socketlist2[currentClient] = new SocketModel(s); }
public void TransData(SocketModel s, string str) { if (CurrentPlayer.SocketPlayer == s) { data = str; } }
public void TransData(SocketModel s, string str) { if (CurrentPlayer == s.GetRemoteEndpoint()) { data = str; } }
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); }
public void Cancel(SocketModel s) { for (int i = 0; i < players.Count; i++) { if (players[i].SocketPlayer == s) { players[i].PlayerStatus = false; } } }
//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); } } }
//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]); } } }
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"); }
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); }
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; } }
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); }
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()); } }
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); }
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); }
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); }
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(); } } }
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(); } }
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()); } }
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()); } }
public Player(SocketModel s) { SocketPlayer = s; PlayerStatus = false; }
public void Add(SocketModel s) { players.Add(new Player(s)); }
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(); } }
public int RoomCreate(SocketModel sm) { Room.Add(new Room1(sm)); return(Room.Count - 1); }
public Room1(SocketModel sm) { Add(sm); InitCards(); Mix(); }