// int count = 0; public ZeroGPacket SendNewPlayerInfo() { try { GameLevelInfo levelnfo = new GameLevelInfo(); levelnfo.Generate("Urban_02", 4, 2, false); // GamePacket packet = new GamePacket(); //packet.packetType = "LevelInfo"; // LoadingComplete packetSecond = new LoadingComplete(); // packetSecond.Generate(true, "yo"); // if(count == 2) // { // packet.Generate("LevelInfo", levelnfo, packetSecond); // } // else // { // packet.Generate("LevelInfo", levelnfo,packetSecond); // } // count = count + 1; ZeroGPacket packet = PacketGenerator.Generate("LevelInfo", levelnfo); return(packet); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message + ex.StackTrace); return(null); } }
public void Process(ZeroGPacket packet) { GamePacket origPacket = PacketGenerator.Decompile(packet); if (packet.PacketType == "LevelInfo" && (origPacket.GetType() == typeof(GameLevelInfo))) { GameLevelInfo newPacket = (GameLevelInfo)origPacket; LevelInfoProcessor.Process(newPacket); } else if (packet.PacketType == "PlayerNames" && (origPacket.GetType() == typeof(PlayerNames))) { PlayerNames newpacket = (PlayerNames)origPacket; PlayerNamesProcessor.Process(newpacket); } else if (packet.PacketType == "PlayerPosition" && (origPacket.GetType() == typeof(PlayerPosition))) { PlayerPosition newpacket = (PlayerPosition)origPacket; PlayerPositionProcessor.Process(newpacket); } else if (packet.PacketType == "AllLoaded" && (origPacket.GetType() == typeof(AllPlayersLoaded))) { AllPlayersLoaded newpacket = (AllPlayersLoaded)origPacket; AllPlayersLoadedProcessor.Process(newpacket); } }
public void Send(ZeroGPacket packet, DeliveryMethod deliveryMethod) { NetPeer[] peers = client.GetPeers(); foreach (NetPeer peer in peers) { peer.Send(netPackProc.Write(packet), deliveryMethod); } }
public void SendPlayerUpdate(Vector3 position, Quaternion rotation) { PlayerPosition packet = new PlayerPosition(); packet.Generate(userName, ConvertCustomTypes.ConvertVectorSerializable(position), ConvertCustomTypes.ConvertQuaternionSerializable(rotation)); ZeroGPacket mainPacket = PacketGenerator.Generate("PlayerPosition", packet); gClient.Send(mainPacket, LiteNetLib.DeliveryMethod.Unreliable); }
public void SendToOthers(ZeroGPacket packet, DeliveryMethod deliveryType, NetPeer sender) { foreach (NetPeer peer in server.GetPeers()) { if (peer != sender) { peer.Send(localPacketProcessor.Write(packet), deliveryType); } } }
private void EventSender_AllPlayersLoaded(object sender, EventArgs e) { // throw new NotImplementedException(); AllPlayersLoaded packet = new AllPlayersLoaded(); packet.Generate(true); ZeroGPacket fullPacket = PacketGenerator.Generate("AllLoaded", packet); serverInst.SendToAll(fullPacket, DeliveryMethod.ReliableOrdered); }
public void SendLoadingComplete() { WriteLog.Verbose("Sending loading complete message to server"); LoadingComplete completePacket = new LoadingComplete(); completePacket.Generate(true, userName); // GamePacket mainPacket = new GamePacket(); // mainPacket.Generate("LoadingComplete", null, completePacket); ZeroGPacket packet = PacketGenerator.Generate("LoadingComplete", completePacket); gClient.Send(packet, LiteNetLib.DeliveryMethod.ReliableOrdered); }
public void OnDataRecieve(ZeroGPacket packet, NetPeer peer) { try { // Console.WriteLine("recieved data from client " + peer.Id + " at " + peer.EndPoint + ", processing"); zeroPacketProcessor.Process(packet, peer); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message + ex.StackTrace); } }
private void CountDownTimer_Elapsed(object sender, ElapsedEventArgs e) { // throw new NotImplementedException(); Console.WriteLine("60 sec elapsed, starting game"); GameLevelInfo packet = new GameLevelInfo(); packet.Generate(levelname, players.PlayersCount() - 1, 3, false); ZeroGPacket fullPacket = PacketGenerator.Generate("LevelInfo", packet); serverInst.SendToAll(fullPacket, DeliveryMethod.ReliableOrdered); countDownTimer.Stop(); }
private void Listener_PeerConnectedEvent(NetPeer peer) { //throw new NotImplementedException(); resetEvent.Set(); WriteLog.Debug("Successfully connected to server, sending info: " + peer.EndPoint); ClientInfo packet = new ClientInfo(); packet.Generate(playername); ZeroGPacket mainPacket = PacketGenerator.Generate("ClientInfo", packet); peer.Send(netPackProc.Write(mainPacket), DeliveryMethod.ReliableOrdered); }
public void Process(ZeroGPacket packet, NetPeer peer) { GamePacket origPacket = PacketGenerator.Decompile(packet); if (packet.PacketType == "LoadingComplete" && (origPacket.GetType() == typeof(LoadingComplete))) { LoadingComplete newPacket = (LoadingComplete)origPacket; // Console.WriteLine("Player " + newPacket.userName + " has set loading complete status to " + newPacket.isComplete); LoadingCompleteProcessor.Process(newPacket); } else if (packet.PacketType == "ClientInfo" && (origPacket.GetType() == typeof(ClientInfo))) { ClientInfo newPacket = (ClientInfo)origPacket; ClientInfoProcessor.Process(newPacket, peer.Id); } else if (packet.PacketType == "PlayerPosition" && (origPacket.GetType() == typeof(PlayerPosition))) { PlayerPositionProcessor.Process(packet, peer); } }
private void OnMaxPlayersReached(object sender, EventArgs e) { Console.WriteLine("max players reached"); PlayerNames packet2 = new PlayerNames(); List <string> playerName = new List <string>(); foreach (Player player in players.PlayersList) { playerName.Add(player.PlayerName); } packet2.Generate(playerName); ZeroGPacket mainPacket2 = PacketGenerator.Generate("PlayerNames", packet2); serverInst.SendToAll(mainPacket2, DeliveryMethod.ReliableOrdered); GameLevelInfo packet = new GameLevelInfo(); packet.Generate(levelname, players.PlayersCount() - 1, 3, isReverse); ZeroGPacket fullPacket = PacketGenerator.Generate("LevelInfo", packet); serverInst.SendToAll(fullPacket, DeliveryMethod.ReliableOrdered); countDownTimer.Stop(); }
public void SendToAll(ZeroGPacket packet, DeliveryMethod deliveryType) { server.SendToAll(localPacketProcessor.Write(packet), deliveryType); }
void ProcessPacket(ZeroGPacket packet, NetPeer peer) { packetProcessor.Process(packet); }
public static void Process(ZeroGPacket packet, NetPeer sender) { Server serverInst = InstanceKeeper.GetServerInstance(); serverInst.SendToOthers(packet, DeliveryMethod.Unreliable, sender); }