Ejemplo n.º 1
0
 void Client_CharacterSelection(CharacterSelectInfo obj)
 {
     cinfo = obj;
     foreach (var info in cinfo.Characters)
     {
         ResolveNicknames(info);
     }
     state.ui.CallEvent("characterlist");
 }
Ejemplo n.º 2
0
        //Server List
        void ConstructServerList()
        {
            manager.Elements.Clear();
            manager.AnimationComplete -= ConstructServerList;
            serverList = new UIServerList(manager)
            {
                Internet = internetServers
            };
            serverList.Selected += ServerList_Selected;
            manager.Elements.Add(serverList);
            manager.Elements.Add(new UIMenuButton(manager, new Vector2(0.01f, -0.55f), "SET FILTER", null));
            manager.Elements.Add(new UIMenuButton(manager, new Vector2(-0.64f, -0.55f), "MAIN MENU", ServersToMainMenu));
            manager.FlyInAll(FLYIN_LENGTH, 0.05);
            //Refresh button - from right
            var rfrsh = new UIMenuButton(manager, new Vector2(0.67f, -0.55f), "REFRESH LIST", RefreshServerList);

            rfrsh.Animation = new FlyInRight(rfrsh.UIPosition, 0, FLYIN_LENGTH);
            rfrsh.Animation.Begin();
            manager.Elements.Add(rfrsh);
            //Connect button - from right
            connectButton           = new UIMenuButton(manager, new Vector2(0.67f, -0.82f), "CONNECT >");
            connectButton.Animation = new FlyInRight(connectButton.UIPosition, 0, FLYIN_LENGTH);
            connectButton.Animation.Begin();
            manager.Elements.Add(connectButton);
            //SERVER DESCRIPTION - from right
            serverDescription = new UIServerDescription(manager, -0.32f, -0.81f)
            {
                ServerList = serverList
            };
            serverDescription.Animation = new FlyInRight(serverDescription.UIPosition, 0, FLYIN_LENGTH);
            serverDescription.Animation.Begin();
            manager.Elements.Add(serverDescription);
            manager.PlaySound("ui_motion_swish");
            if (netClient == null)
            {
                netClient = new GameClient(Game);
                netClient.Disconnected     += ServerList_Disconnected;
                netClient.ServerFound      += NetClient_ServerFound;
                netClient.OpenNewCharacter += NetClient_OpenNewCharacter;
                netClient.Start();
                netClient.UUID = Game.Config.UUID.Value;
                netClient.CharacterSelection += (info) =>
                {
                    csel = info;
                    manager.FlyOutAll(FLYIN_LENGTH, 0.05);
                    manager.PlaySound("ui_motion_swish");
                    manager.AnimationComplete += ConstructCharacterSelect;
                    netClient.Disconnected    -= ServerList_Disconnected;
                };
            }
            netClient.DiscoverLocalPeers();
            if (internetServers)
            {
                netClient.DiscoverGlobalPeers();
            }
        }
Ejemplo n.º 3
0
        void NetworkThread()
        {
            var conf = new NetPeerConfiguration(NetConstants.DEFAULT_APP_IDENT);

            client = new NetClient(conf);
            client.Start();
            NetIncomingMessage im;

            while (running)
            {
                while ((im = client.ReadMessage()) != null)
                {
                    /*try
                     * {*/
                    switch (im.MessageType)
                    {
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                        FLLog.Info("Lidgren", im.ReadString());
                        break;

                    case NetIncomingMessageType.DiscoveryResponse:
                        if (ServerFound != null)
                        {
                            var info = new LocalServerInfo();
                            info.EndPoint       = im.SenderEndPoint;
                            info.Name           = im.ReadString();
                            info.Description    = im.ReadString();
                            info.CurrentPlayers = im.ReadInt32();
                            info.MaxPlayers     = im.ReadInt32();
                            mainThread.QueueUIThread(() => ServerFound(info));
                        }
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        var status = (NetConnectionStatus)im.ReadByte();
                        if (status == NetConnectionStatus.Disconnected)
                        {
                            connecting = false;
                            Disconnected(im.ReadString());
                        }
                        break;

                    case NetIncomingMessageType.Data:
                        var kind = (PacketKind)im.ReadByte();
                        if (connecting)
                        {
                            if (kind == PacketKind.Authentication)
                            {
                                FLLog.Info("Net", "Authentication Packet Received");
                                var authkind = (AuthenticationKind)im.ReadByte();
                                if (authkind == AuthenticationKind.Token)
                                {
                                    FLLog.Info("Net", "Token");
                                    AuthenticationRequired(im.ReadString());
                                }
                                else if (authkind == AuthenticationKind.GUID)
                                {
                                    FLLog.Info("Net", "GUID");
                                    var response = client.CreateMessage();
                                    response.Write((byte)PacketKind.Authentication);
                                    response.Write((byte)AuthenticationKind.GUID);
                                    var arr = UUID.ToByteArray();
                                    foreach (var b in arr)
                                    {
                                        response.Write(b);
                                    }
                                    client.SendMessage(response, NetDeliveryMethod.ReliableOrdered);
                                }
                                else
                                {
                                    client.Shutdown("Invalid Packet");
                                }
                            }
                            else if (kind == PacketKind.AuthenticationSuccess)
                            {
                                connecting = false;
                                var inf = new CharacterSelectInfo();
                                inf.ServerNews = im.ReadString();
                                mainThread.QueueUIThread(() => CharacterSelection(inf));
                            }
                            else
                            {
                                client.Shutdown("Invalid Packet");
                            }
                            break;
                        }
                        switch (kind)
                        {
                        case PacketKind.NewCharacter:
                            if (im.ReadByte() == 1)
                            {
                                var credits = im.ReadInt32();
                                OpenNewCharacter(credits);
                            }
                            break;
                        }
                        break;
                    }

                    /*}
                     * catch (Exception)
                     * {
                     *      FLLog.Error("Net", "Error reading message of type " + im.MessageType.ToString());
                     * throw;
                     * }*/
                    client.Recycle(im);
                }
                Thread.Sleep(1);
            }
            FLLog.Info("Lidgren", "Client shutdown");
            client.Shutdown("Shutdown");
        }