Knight Online Private Serverlar
Knight Online Private Serverlar

Knight Online Private Serverlar Hakkındaki Tüm Paylaşımlar.
 
AnasayfaTakvimSSSAramaÜye ListesiKullanıcı GruplarıKayıt OlGiriş yap

Paylaş | 
 

 [C#] Ebenezer Bi-Frost Aktifleştirmek

Aşağa gitmek 
YazarMesaj
Corleone
Administrator
Administrator
avatar

Tuttuğu Takım : Beşiktaşlı
Ruh Hâli : Neşeli
Mesaj Sayısı : 1541
Kullanıcı Puanı : 35001
Saygınlık : 10381
+500 Repliler
Üyelik Tarihi : 24/07/09
Yaş : 23
Şubesi : Ä°stanbul

MesajKonu: [C#] Ebenezer Bi-Frost Aktifleştirmek   Çarş. Ağus. 12, 2009 10:23 pm

Kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Threading;
using System.IO;


namespace GameMonitor
{
public class Bifrost
{
//Declare variables

static short state = 0;//0 = off,1 = running, 2 = in process, 3 = error
static Boolean EventOpen = false;
static Boolean Monitor = false;
static int start1 = 0;
static int start2 = 0;
static int start3 = 0;
static int eventno = 0;
static DateTime nextaction = DateTime.Now;
static Thread t = new Thread(new ThreadStart(StartMonitor));
static Boolean WarningSent = false;


DateTime end = DateTime.Now;

public static void UpdateState(short newstate)
{

state = newstate;
switch (state)
{
case 0: Console.WriteLine("Monitor Stopped"); Monitor = false; EventOpen = false; t.Abort(); break;
case 1: Console.WriteLine("Monitor Started."); Monitor = true; break;
case 2: Console.WriteLine("In Process..."); break;
case 3: Console.WriteLine("Error.."); break;
case 4: Console.WriteLine("Thread Created."); break;

}
}
public static void StopMonitor()
{
UpdateState(0);
}


public static void MakeAnnouncement(int type)
{
if (type == 1)
{
Console.WriteLine("The Bifrost has opened!");
SendMessage.EbenezerSendMessage("The Bifrost has Opened!");
}
else if (type == 2)
{
Console.WriteLine("The Bifrost has Closed!");
SendMessage.EbenezerSendMessage(string.Format("The Bifrost has Closed! The Next Bifrost is at {0}",GetNext()));
WarningSent = false;
}
}
public static void CheckTime()
{
if (!WarningSent)
{
if (DateTime.Now.Hour == start1 - 1 && DateTime.Now.Minute == 55)
{
SendMessage.EbenezerSendMessage("Bifrost will begin in 5 minutes!");
WarningSent = true;
}
if (DateTime.Now.Hour == start2 - 1 && DateTime.Now.Minute == 55)
{
SendMessage.EbenezerSendMessage("Bifrost will begin in 5 minutes!");
WarningSent = true;
}
if (DateTime.Now.Hour == start3 - 1 && DateTime.Now.Minute == 55)
{

SendMessage.EbenezerSendMessage("Bifrost will begin in 5 minutes!");
WarningSent = true;
}
}
switch (DateTime.Now.Hour)
{

case 4:
EventOpen = true;
eventno = 1;
MakeAnnouncement(1);
break;
case 11:
EventOpen = true;
eventno = 2;
MakeAnnouncement(1);
break;
case 18:
EventOpen = true;
eventno = 3;
MakeAnnouncement(1);
break;
}

}
public static void Start()
{
t.Start();
UpdateState(4);
UpdateState(1);
}
public static void StartMonitor()
{

try
{
OdbcConnection MyConnection = new OdbcConnection(
"DRIVER={SQL SERVER}" + String.Format(";SERVER=SERVER;DATABASE={0};UID={1};PWD={2}", Program.database.Trim(), Program.user.Trim(), Program.pw.Trim()));
MyConnection.Open();

OdbcCommand DbCommand = MyConnection.CreateCommand();
DbCommand.CommandText = "SELECT bstarttime1,bstarttime2,bstarttime3 from MONSTER_CHALLENGE where sindex = #";
OdbcDataReader datareader = DbCommand.ExecuteReader();
while (datareader.Read())
{

start1 = datareader.GetInt16(0);
start2 = datareader.GetInt16(1);
start3 = datareader.GetInt16(2);
}
datareader.Close();
datareader.Dispose();
DbCommand.Dispose();
while (Monitor)
{

CheckTime();

if (EventOpen && Monitor)
{

Console.WriteLine(String.Format("Open: Current: {0} End: {1}", DateTime.Now.Hour, GetEvent(eventno)));
}
while (EventOpen && Monitor)
{


//1 hour past event close it
//If current hour is 11 it is more than 5 and will cause
//The event area to be closed.
//Need a way to make that not happen
//

if (DateTime.Now.Hour >= start1 + 1 && eventno == 1)
{
Console.WriteLine(String.Format("Closing Event {2}: Current: {0} End: {1}", DateTime.Now.Hour, GetEvent(eventno), eventno));
CloseEvent();
}

if (DateTime.Now.Hour >= start2 + 1 && eventno == 2)
{
Console.WriteLine(String.Format("Closing Event {2}: Current: {0} End: {1}", DateTime.Now.Hour, GetEvent(eventno), eventno));
CloseEvent();
}

if (DateTime.Now.Hour >= start3 + 1 && eventno == 3 || DateTime.Now.Hour <= GetNext() && eventno == 3)
{
Console.WriteLine(String.Format("Closing Event {2}: Current: {0} End: {1}", DateTime.Now.Hour, GetEvent(eventno), eventno));
CloseEvent();
}



Thread.Sleep(10);

}
Thread.Sleep(10);
}
}
catch (Exception e)
{
File.AppendAllText("exceptionlog.txt", e.Message + "\n");
}

}


public static void DisconnectUsers()
{

while (!EventOpen && Monitor)
{
try
{
OdbcConnection MyConnection = new OdbcConnection(
"DRIVER={SQL SERVER}" + String.Format(";SERVER=LOSTSOULZ;DATABASE={0};UID={1};PWD={2}", Program.database.Trim(), Program.user.Trim(), Program.pw.Trim()));
MyConnection.Open();

OdbcCommand DbCommand = MyConnection.CreateCommand();
DbCommand.CommandText = "SELECT strcharid from knight_account.dbo.currentuser where strcharid in (select struserid from kn_online.dbo.userdata where zone = 31)";
OdbcDataReader datareader = DbCommand.ExecuteReader();

while (datareader.Read())
{
Console.WriteLine(datareader.GetString(0).Trim() + " Disconnected @ {0}", DateTime.Now.ToString());
SendMessage.EbenezerSendMessage(string.Format("/kill {0}", datareader.GetString(0).Trim()));
}

datareader.Close();
datareader.Dispose();
DbCommand.Dispose();
MyConnection.Close();
MyConnection.Dispose();

Thread.Sleep(10);
CheckTime();
}
catch (Exception e)
{
File.AppendAllText("exceptionlog.txt", e.Message + "\n");
}
}

}
public static void CloseEvent()
{
EventOpen = false;
MakeAnnouncement(2);
DisconnectUsers();
}
public static int GetEvent(int num)
{
switch (num)
{
case 1:
return 5;
case 2:
return 12;
case 3:
return 19;
default: return 0;

}
}
public static int GetNext()
{
switch (DateTime.Now.Hour)
{
//5 11 22
case 1:
return 4;
case 2:
return 4;
case 3:
return 4;
case 4:
return 11;
case 5:
return 11;
case 6:
return 11;
case 7:
return 11;
case 8:
return 11;
case 9:
return 11;
case 10:
return 11;
case 11:
return 18;
case 12:
return 18;
case 13:
return 18;
case 14:
return 18;
case 15:
return 18;
case 16:
return 18;
case 17:
return 18;
case 18:
return 4;
case 19:
return 4;
case 20:
return 4;
case 21:
return 4;
case 22:
return 4;
case 23:
return 4;
case 0:
return 4;


default: return 0;

}
}


//Announce event "name" over
//Check users in event zone

//disconnect user SendEbenezermessage()

//log disconnect to txt/console window

//Announce Event zone closed
}
}
Sayfa başına dön Aşağa gitmek
Kullanıcı profilini gör http://k2private.yetkin-forum.com
 
[C#] Ebenezer Bi-Frost Aktifleştirmek
Sayfa başına dön 
1 sayfadaki 1 sayfası

Bu forumun müsaadesi var:Bu forumdaki mesajlara cevap veremezsiniz
Knight Online Private Serverlar :: Programlama :: .NET Programlama Dilleri-
Buraya geçin: