public void OnReciveShort(MessageToOneClient msg) //连接是否成功 { if (msg.MessageType == MessageType.ValidPlayer) { } else { MessageBox.Show("Invalid Player"); Starting starting = new Starting(); Application.Run(starting); MessageToServer msg1 = new MessageToServer(); msg1.MessageType = MessageType.AddPlayer; Program.watch = starting.watch; Program.teamID = Program.watch?1911:starting.teamid; Program.playerID = Program.watch ? 1911 : starting.playerid; Program.jobType = starting.job; Program.clientCommunicator.Stop(); msg1.TeamID = Program.teamID; msg1.PlayerID = Program.playerID; msg1.JobType = starting.job; if (Program.clientCommunicator.Connect("127.0.0.1", starting.port)) { Program.clientCommunicator.SendMessage(msg1); } else { MessageBox.Show("连接Agent失败"); return; } } }
public void OnReciveShort(MessageToOneClient msg) //连接是否成功 { if (msg.MessageType == MessageType.ValidPlayer) { } else { MessageBox.Show("Invalid Player"); Starting starting = new Starting(); Application.Run(new Starting()); MessageToServer msg1 = new MessageToServer(); msg1.MessageType = MessageType.AddPlayer; msg1.TeamID = starting.teamid; msg1.PlayerID = starting.playerid; msg1.JobType = starting.job; Program.clientCommunicator.SendMessage(msg1); } }
static void Main(string[] args) { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //取得开始命令 AOption?options = null; Parser.Default.ParseArguments <AOption>(args).WithParsed(o => { options = o; }); Int64 teamid, playerid; ClientData client; if (options == null) { Starting starting = new Starting(); Application.Run(starting); teamid = starting.teamid; playerid = starting.playerid; client = new ClientData(starting.teamid, starting.playerid, starting.job, starting.port); } else { teamid = options.teamID; playerid = options.playerID; client = new ClientData(options.teamID, options.playerID, (JobType)options.job, options.ServerPort); } if (clientCommunicator.Connect("127.0.0.1", client.port)) { } else { MessageBox.Show("连接Agent失败"); return; } //向server发消息 MessageToServer msg = new MessageToServer(); msg.MessageType = MessageType.AddPlayer; msg.TeamID = teamid; msg.PlayerID = playerid; msg.JobType = client.jobType; //TO DO:发出消息 clientCommunicator.OnReceive += delegate() { if (clientCommunicator.TryTake(out IMsg msg)) { client.messageline.Add(new Tuple <IMsg, long>(msg, System.Environment.TickCount64)); } }; client.messageline = new BlockingCollection <Tuple <IMsg, long> >(); int bulletspeed; switch (client.jobType) { default: case JobType.Job0: bulletspeed = Program.basicBulletMoveSpeed; break; case JobType.Job1: bulletspeed = Program.basicBulletMoveSpeed * 2; break; case JobType.Job2: bulletspeed = Program.basicBulletMoveSpeed / 2; break; case JobType.Job3: bulletspeed = Program.basicBulletMoveSpeed / 2; break; case JobType.Job4: bulletspeed = Program.basicBulletMoveSpeed * 4; break; case JobType.Job5: bulletspeed = Program.basicBulletMoveSpeed; break; case JobType.Job6: bulletspeed = Program.basicBulletMoveSpeed; break; } client.gameform = new Form1(teamid, playerid, bulletspeed, client.jobType); new Thread(() => { while (true) { if (client.messageline.TryTake(out Tuple <IMsg, long> msg)) { if (msg.Item1.PacketType == PacketType.MessageToOneClient) { MessageToOneClient mm = msg.Item1.Content as MessageToOneClient; if (mm.TeamID == teamid && mm.PlayerID == playerid) { client.OnReciveShort(mm); } } else if (msg.Item1.PacketType == PacketType.MessageToClient) { MessageToClient mm = msg.Item1.Content as MessageToClient; if (mm.TeamID == teamid && mm.PlayerID == playerid) { client.OnReciveNormal(mm, msg.Item2); } } } } } ).Start(); clientCommunicator.SendMessage(msg); Application.Run(client.gameform); Application.Exit(); }